3

The obvious doesn't catch the LF characters

foo.Replace(Environment.NewLine, String.Empty)

Nor does...

foo.Replace("\r\n", "").Replace("\n", "").Replace("\r", "")

The file itself is a multi line XML file. Line feed characters before the XML declaration invalidate the string.

mmcglynn
  • 7,668
  • 16
  • 52
  • 76
  • 1
    What do tab characters have to do with linefeeds? – Hans Passant Mar 10 '10 at 17:31
  • Have you tried ControlChars.CrLf? – Stewbob Mar 10 '10 at 17:32
  • What is the value of "replacewith", and how are you using the code above. You have posted only a tiny fragment of what you want, and not a "complete code" - it is hard to know what you're looking for. – Steven_W Mar 10 '10 at 17:33
  • My bet is that you are after a wrong problem. Possibly you've got a BOM at the beginning or other such problem? Make sure that it actually is a newline that you are dealing with. – Tronic Mar 10 '10 at 17:33
  • 2
    Youre probably just lacking foo = foo.Replace..... – Alxandr Mar 10 '10 at 17:36
  • Fixed flaws in the question. nobugz - meant to say line feeds. Steven_W - removed the variable reference. Stewbob - will try that, good thought. – mmcglynn Mar 10 '10 at 17:37
  • ControlChars.Lf - worked, big ups to Stewbob – mmcglynn Mar 10 '10 at 17:39

1 Answers1

7

VB.NET doesn't use the C style escapes for CR or LF. In VB, your second example translates to:

foo.Replace(vbNewLine, replaceWith).Replace(vbLF, replaceWith).Replace(vbCR, replaceWith)
Mark Brackett
  • 84,552
  • 17
  • 108
  • 152