如何从一个字符串中删除换行符?字符串、换行符

2023-09-02 01:44:39 作者:罒小呆一直在

我有一个字符串按以下格式

I have a string in the following format

string s = "This is a Test String.n   This is a next line.t This is a tab.n'

我想删除的所有出现ñ r 从上面的字符串。

I want to remove all the occurrences of n and r from the string above.

我已经试过字符串s = s.Trim(新的char [] {' N',' r'}); ,但它并没有帮助。

I have tried string s = s.Trim(new char[] {'n', 'r'}); but it didn't help.

推荐答案

我喜欢用普通的前pressions。在这种情况下,你可以这样做:

I like to use regular expressions. In this case you could do:

string replacement = Regex.Replace(s, @"t|n|r", "");

正前pressions不是在.NET世界最新流行的,因为他们是在动态语言,但它们提供大量的电力来操作字符串。

Regular expressions aren't as popular in the .NET world as they are in the dynamic languages, but they provide a lot of power to manipulate strings.

 
精彩推荐
图片推荐