Clean String Functions - Remove Unwanted Characters: Difference between revisions
Jump to navigation
Jump to search
Jkuehlthau (talk | contribs) (Created page with "Source: http://www.code-tips.com/2009/04/vbscript-string-clean-function-remove.html =Specify specific characters to remove or replace= <source lang="vbscript"> Function strCl...") |
Jkuehlthau (talk | contribs) No edit summary |
||
Line 2: | Line 2: | ||
=Specify specific characters to remove or replace= | =Specify specific characters to remove or replace= | ||
<source lang=" | <source lang="vb"> | ||
Function strClean (strtoclean) | Function strClean (strtoclean) | ||
Dim objRegExp, outputStr | Dim objRegExp, outputStr | ||
Line 20: | Line 20: | ||
=Remove all characters except specific characters, or a range of characters by allowing specific ranges (eg. a-z, A-Z, 0-9)= | =Remove all characters except specific characters, or a range of characters by allowing specific ranges (eg. a-z, A-Z, 0-9)= | ||
<source lang=" | <source lang="vb"> | ||
Function strClean (strtoclean) | Function strClean (strtoclean) | ||
Dim objRegExp, outputStr | Dim objRegExp, outputStr |
Latest revision as of 19:16, 29 March 2016
Source: http://www.code-tips.com/2009/04/vbscript-string-clean-function-remove.html
Specify specific characters to remove or replace
Function strClean (strtoclean) Dim objRegExp, outputStr Set objRegExp = New Regexp objRegExp.IgnoreCase = True objRegExp.Global = True objRegExp.Pattern = "[(?*"",\\<>&#~%{}+_.@:\/!;]+" outputStr = objRegExp.Replace(strtoclean, "-") objRegExp.Pattern = "\-+" outputStr = objRegExp.Replace(outputStr, "-") strClean = outputStr End Function
Remove all characters except specific characters, or a range of characters by allowing specific ranges (eg. a-z, A-Z, 0-9)
Function strClean (strtoclean) Dim objRegExp, outputStr Set objRegExp = New Regexp objRegExp.IgnoreCase = True objRegExp.Global = True objRegExp.Pattern = "((?![a-zA-Z0-9]).)+" outputStr = objRegExp.Replace(strtoclean, "-") objRegExp.Pattern = "\-+" outputStr = objRegExp.Replace(outputStr, "-") strClean = outputStr End Function