Thursday, December 22, 2011

VBScript : unQuoteString()

This small function removes the quotes from a quoted string (or any two identical characters that "wraps" a string)
Function unQuoteString(str, quot)
 Dim res : res = Trim(str)
 if Left(res,1) & Right(res,1) = quot & quot Then res = MID(res,2, LEN(res)-2)
 unQuoteString = res
End Function

'== EXAMPLE ==
myString = """" & "Hello World!" & """"
wscript.echo "Before: " & myString '-> Before: "Hello World"
wscript.echo "After: " & unQuoteString(myString,"""") '-> After: Hello World

'

No comments:

Post a Comment