Gravatar Ben Ramey's Blog
Scripture, programming problems, solutions and stories.

Replacing newline characters in VB.NET strings

I’m not very familiar (which I am actually very happy for!) with VB.NET and so I had a hard time figuring out how to trim newline characters from a string in a Reporting Services report I was working on.

Turns out none of the “regular” methods really work. The Trim function only removes spaces and anything like Replace(“string”, “\n”, “”) didn’t work.

You have to use the Chr(13) or Chr(10) functions to actually get the character values for the newline characters. So, my solution looked like this:

Replace(Replace(stringVariable, Chr(10), “”), Chr(13), “”)

Thanks to this forum post for providing the clues: http://www.daniweb.com/forums/thread54797.html

Comments