Click to See Complete Forum and Search --> : how to replace / \ : * ? " < > | with _


psn
06-14-2005, 07:41 AM
My string contains characters as follows / \ : * ? " < > |
I want to replace all of this characters by _

For Eg: Mystring=hello/all\?:to"<>*you

After Replacing: Newstring=hello_all___to____you

I tried as follows: Newstring=replace(Mystring, "/" , "_")

This works fine for only single character. But what code should I write to replace all above characters with _ at one shot.

Can anybody help me.

Regards

phpnovice
06-14-2005, 11:49 AM
Answer: Regular Expressions

Set re = Server.CreateObject("VBScript.RegExp")
re.Global = True
re.IgnoreCase = True
re.MultiLine = False
re.Pattern = "[\/\\\:\*\?\""\<\>\|]"
mystring = re.Replace(mystring, "_")