How to Trim Spaces Before or After an XML?

Hi folks!

I’m using a textInputStream in order to show an XML file in a textArea, this is my code:

[code] Dim DecodedText As String

///Leyendo el XML para ver si tiene espacios en blanco
Dim AppFolder As FolderItem = SpecialFolder.Desktop.Child(“test.xml”)
If AppFolder <> Nil Then
If AppFolder .Exists Then

  Dim t As TextInputStream
  Try
    t = TextInputStream.Open(AppFolder)
    t.Encoding = Encodings.UTF8
    DecodedText = t.ReadAll
    t.Close
  Catch e As IOException
    MsgBox("Error accessing file.")
  End Try
End If

End If

txtXMLViewer.text = DecodedText.ReplaceAll(Chr(13),"")[/code]

The idea is the next, when I open an XML file that has spaces before start the code, delete that spaces, also I tried with TRIM,but without results. :frowning:
What Am i doing wrong?

If trim isn’t removing the “spaces” then they’re not spaces or tabs, carriage returns or line feeds or any of the other whitespace that trim is intended to remove

They’re other “gremlins”

There’s likely a regex that could identify and replace those
Or you could run a loop that does a replaceall on characters - but that means you’d have to know all non-printing characters

Your best bet is to break into the debugger at the last line and examine the bytes behind DecodedText to see what’s really going on.

Also, use ReplaceLineEndings instead of trying to replace the EOL character yourself.

[quote=265281:@Norman Palardy]If trim isn’t removing the “spaces” then they’re not spaces or tabs, carriage returns or line feeds or any of the other whitespace that trim is intended to remove

They’re other “gremlins”

There’s likely a regex that could identify and replace those
Or you could run a loop that does a replaceall on characters - but that means you’d have to know all non-printing characters[/quote]
But I made this Carriage returns to the test.xml file, in order to simulate that problem.

Is this a file you can post somewhere so we can examine its contents?

Thats a Sample of the XML: https://drive.google.com/open?id=0B2es6eiEdQJdU0VRZVd2YnotNW8

Whatever you used to generate that text file prefixed a UTF-8 BOM.

FYI, my M_String module has code that will strip the BOM from text.

Thanks all, I done it, Changing Chr 13 to Chr 10:

As I said above…