Clean String Functions - Remove Unwanted Characters: Difference between revisions

From Starfish ETL
Jump to navigation Jump to search
(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...")
 
No edit summary
 
Line 2: Line 2:


=Specify specific characters to remove or replace=
=Specify specific characters to remove or replace=
<source lang="vbscript">
<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="vbscript">
<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