mmcglynn
mmcglynn

Reputation: 7672

Replace line feed (LF) characters in a String using VB.NET

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.

Upvotes: 3

Views: 13799

Answers (1)

Mark Brackett
Mark Brackett

Reputation: 85685

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)

Upvotes: 7

Related Questions