Tips for handling special characters within scripts...???

Andrew Angell
Andrew Angell used Ask the Experts™
on
I often find myself having to deal with special characters causing errors in my scripts.  Usually it's where SQL is involved because an apostrphy is included in the value that's getting used in the SQL statement which causes a parsing error.  I fix this in these instances by using something similar to:

var = Replace(var, "'", "''")

So that works for small things like a name field, or an address field, and for SQL with apostrophy's.  But here's an instance where I'm actually saving an XML response to disk like this:

set fs = CreateObject("Scripting.FilesystemObject")
filename = Server.MapPath("../xml/eBay/GetItemResponse_"&eBayItemID&".xml")
set tfile=fs.CreateTextFile(filename, true)
tfile.WriteLine(xmlResponse)
tfile.Close
set tfile = nothing
set fs = nothing

This works 98% of the time, however, I came across an order today where the address included in the response was the following:

Ulrich Braun
Enzianstraße 34
Waldkraiburg,   84478
Germany

Upong trying to save the file to disk I get an error:

Microsoft VBScript runtime error '800a0005'

Invalid procedure call or argument

I don't think the same fix would work on this because that's an entire XML response.  Replacing all single ' with double '' will just break something else most likely.

Is there any particular way to easily handle these types of things in vbscript so that I don't have to constantly find work-arounds for them?  any info would be great.  thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Andrew AngellCo-Owner / Developer

Author

Commented:
the space between the e and 34 in the address actually contained a Square in the response.  i don't even know how to make a square.
Top Expert 2006
Commented:
You should use unicode if your XML can have that. Change CreateTextFile(filename, true) to

set tfile=fs.CreateTextFile(filename, true, true)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial