osm*_*bin 3 c# regex replace newline
我需要用另一个字符(比如'X')替换字符串中的每个换行符.我不希望用一个换行符折叠多个换行符!
PS:这个正则表达式用一个换行替换所有连续的换行符,但它不是我需要的.
Regex regex_newline = new Regex("(\r\n|\r|\n)+");
Run Code Online (Sandbox Code Playgroud)
Jam*_*ran 15
这将用一些东西替换一个或多个换行符,不一定用一个换行符 - 这是由你没有显示的regex_newline.Replace(...)调用决定的.
所以基本上,答案是
Regex regex_newline = new Regex("(\r\n|\r|\n)"); // remove the '+'
// :
regex_newline.replace(somestring, "X");
Run Code Online (Sandbox Code Playgroud)
小智 8
只需使用该String.Replace
方法并替换Environment.NewLine
您的字符串.不需要正则表达式.
http://msdn.microsoft.com/en-us/library/system.environment.newline.aspx
归档时间: |
|
查看次数: |
12042 次 |
最近记录: |