Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Get rid of \r\n in a string

Tags:

string

c#

I'm trying to get messages from Gmail in C#

but the message body comes like this "\r\n\r\nBODY\r\n\r\n"

How can I get the "BODY" out of the string ?

I tried to loop through it but I found out that when looping the "\r" becomes a " "

like image 396
Hady Hallak Avatar asked Aug 04 '13 11:08

Hady Hallak


2 Answers

You can use String.Trim() to remove all leading and trailing whitespace form a given string. Something like this:

var body = inputString.Trim();

This would cover /r/n characters, as well as any other whitespace.

like image 63
David Avatar answered Oct 02 '22 07:10

David


try this:

string after = text.Replace(Environment.NewLine, "");
like image 29
Yoav Avatar answered Oct 02 '22 05:10

Yoav