replacing an invalid character with a space

I’m reading in an xml file from a website and when I convert it to a plain text file, I’m getting an invalid character (black diamond with a question mark) between some words when viewed in a text editor. If I just go to that web page and save it as source, the character is a carriage return. I need to replace that with a space. Nothing I’ve tried so far has worked, though…

[code]CR = &u0D
LF = &u0A
CRLF = &u0D + &u0A

lineArray(i) = ReplaceLineEndings(lineArray(i)," “)
lineArray(i) = lineArray(i).replaceAll(CR,” “)
lineArray(i) = lineArray(i).replaceAll(LF,” “)
lineArray(i) = lineArray(i).replaceAll(CRLF,” ")[/code]

If I select that black diamond and do a hex dump in Text Wrangler, I get this…
0000: FD FF

So I also tried

lineArray(i) = lineArray(i).replaceAll(&uFDFF," ")

but nothing seems to replace that bad boy.

Unicode &uFDFF is probably not the same at the byte series FD FF.

Instead try it at a Byte level:

Dim bad As String = ChrB(&hFD) + ChrB(&hFF) lineArray(i) = lineArray(i).ReplaceAll(bad, " ")

good idea, but still no luck unfortunately. it’s a pesky little bugger!

Did you define the encoding of the string after fetching it from the internet?

no i did not.

that did it - thanks!