Clean String Functions - Remove Unwanted Characters

Clean String Functions - Remove Unwanted Characters

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
    • Related Articles

    • VBScript Functions

      This is a link to a page that contains all the built-in VBScript functions: https://www.w3schools.com/asp/asp_ref_vbscript_functions.asp
    • Format Phone Number

      Here are a couple of sample functions to help you clean up phone numbers. Function ScriptedField dim oldphone dim phone dim xPos dim plusPos dim extension oldphone="@@ORG:phone_office@@" phone=oldphone if len(phone) <> 0 then 'Remove all non-numberic ...
    • Examples of using StarfishETL Class Functions In Javascript

      This code was used to lookup a value inside of SugarCRM using the Sugar REST connector. function scriptedField() { var res = ""; res = vals["Branch Name"]; if (res) { Starfish.LogMessage(res.toString()); } res = ...
    • Scripting Class Object

      From within VBScript operations (ScriptedVariable, VBScriptProcedure, ScriptedField) in additional to normal VBScript functions, the developer has access to a custom “Starfish” class. The tables below define its usage. This class may also be used ...
    • Salesforce Connector

      Additional Documentation This Connector is based on the Salesforce ADO.NET Provider by CData. For additional help, including Connection String parameters, please see: https://cdn.cdata.com/help/RFG/ado/ Salesforce Origin Case as Origin Table You ...