Taking away a text from a string

T

Tomomichi Amano

Hello!
I just asked a question, but it seems my question wasn't clear enough, so
I'll ask again, simply.

How can I take the LAST text (say "\r\n") from a string value??

So, if
string a="Hello!\r\nHow are you?\r\n";
it would become
a="Hello!\r\nHow are you?";

Thank you in advance!
 
M

Morten Wennevik

As Jon said, with SubString()

string line = "something\r\n";
line = line.Substring(0, line.Length - 2);
 
N

n!

string a="Hello!\r\nHow are you?\r\n";
it would become
a="Hello!\r\nHow are you?";

You can use the 'TrimEnd' method:

string a="Hello!\r\nHow are you?\r\n";

a= a.TrimEnd( '\r', '\n' );

n!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top