Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Given this string (with '\n') how can I strip it from all the returns?

Tags:

string

c#

Here's the string:

\n\n\t\thttp://www.linkedin.com/in/ckenworthy\n\n\t

How can I strip everything so I only end up with:

http://www.linkedin.com/in/ckenworthy

I've tried the following:

string value = doc.XPathSelectElement("/ipb/profile/contactinformation/contact[title/text() = 'LinkedIn']/value").Value;
                value = value.Replace(Environment.NewLine, "");
                return value;

But I always end up with the first line I posted up there. Thank you!

like image 739
Sergio Tapia Avatar asked Dec 01 '25 06:12

Sergio Tapia


2 Answers

value.Trim() will probably do exactly what you want. It will remove all whitespace characters from the start and end of the string.

The reason Environment.NewLine may not work is because its value depends on whether you're running on Windows, Unix or Mac, but that really doesn't matter if you're getting the string from a remote system - the remote system will still return the same newline separator ('\n' in this case).

like image 97
EMP Avatar answered Dec 02 '25 21:12

EMP


Try...

value.Trim()
like image 25
Rob Avatar answered Dec 02 '25 20:12

Rob



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!