I am having a tough time finding a string based replace function to replace anything not A-Z or 0-9 , including spaces, with a dash ( - ). I have found RegEx options, but I am using the code inside of a repeat region, so it will not work. I am trying to make some clean URL's, but cannot get this right. Any help appreicated. Below is one of the many conbinations I have already tried. <%=(Replace(rsGetData.Fields.Item("Title").Value, "[a-z0-9]*", "-")) %> Code (markup):
What you have to do here is pick through each character in the string and determine if it's not acceptable and then replace that character in the string. Something like the following: Dim aChar As Char Dim theTitle As String theTitle = rsGetData.Fields.Item("Title").Value For Each aChar In theTitle If Not ((aChar >= "0" And aChar <= "9") Or (aChar >= "A" And aChar <= "Z") Or (aChar >= "a" And aChar <= "z")) Then Replace(theTitle, theChar, "-") End If Next Code (markup):
Function kCheckRegExp(vPattern, vStr) Dim oRegExp Set oRegExp = New RegExp oRegExp.Pattern = vPattern oRegExp.IgnoreCase = False kCheckRegExp = oRegExp.Test(vStr) Set oRegExp = Nothing End Function Function kLeachRegExp(vStr1, vPattern, vStr2) Dim oRegExp Set oRegExp = New RegExp oRegExp.Pattern = vPattern oRegExp.IgnoreCase = True oRegExp.Global = True kLeachRegExp = oRegExp.Replace(vStr1, vStr2) Set oRegExp = Nothing End Function Code (markup): vstr = kLeachRegExp("string with not a-z 0-9", "[^a-z0-9]+", "")