_StringStripChar() - Strip certain characters from a given string.


SUBMITTED BY: Guest

DATE: May 30, 2013, 7:47 a.m.

FORMAT: Text only

SIZE: 1.5 kB

HITS: 2400

  1. #include <Constants.au3>
  2. MsgBox($MB_SYSTEMMODAL, '', _StringStripChar('This is the C:\Example__Test.*', '\_*'))
  3. MsgBox($MB_SYSTEMMODAL, '', _StringStripChar('It''s not \E\Q, but instead EQ.', '\E\Q'))
  4. ; #FUNCTION# ====================================================================================================================
  5. ; Name ..........: _StringStripChar
  6. ; Description ...: Strip certain characters from a given string.
  7. ; Syntax ........: _StringStripChar($sString, $sChars)
  8. ; Parameters ....: $sString - String to strip character from.
  9. ; $sChars - Characters to be stripped.
  10. ; Return values .: Success - String with replaced characters
  11. ; Failure - Original string and sets @error to non-zero.
  12. ; Author ........: guinness
  13. ; Related .......: http://www.autoitscript.com/forum/topic/96454-my-new-udf/
  14. ; Link ..........: http://www.autoitscript.com/forum/topic/96454-my-new-udf/
  15. ; Example .......: Yes
  16. ; ===============================================================================================================================
  17. Func _StringStripChar($sString, $sChars)
  18. If $sChars == '' Then Return SetError(1, 0, $sString)
  19. If $sString == '' Then Return SetError(2, 0, $sString)
  20. $sChars = StringReplace($sChars, '\E', 'E\')
  21. $sChars = StringReplace($sChars, '\Q', 'Q\')
  22. Return StringRegExpReplace($sString, '[\Q' & $sChars & '\E]', '')
  23. EndFunc ;==>_StringStripChar

comments powered by Disqus