开发者

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

开发者 https://www.devze.com 2023-01-05 21:57 出处:网络
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:

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!


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).


Try...

value.Trim()
0

精彩评论

暂无评论...
验证码 换一张
取 消