我需要用另一个字符(例如“X”)替换字符串中的每个换行符。我做了,而不是,希望用一个换行符折叠多个换行符!
PS:这个正则表达式用一个换行符替换所有连续的换行符,但这不是我所需要的。
Regex regex_newline = new Regex("(\r\n|\r|\n)+");发布于 2013-01-26 20:24:56
它将用某种东西替换一个或多个换行符,而不一定是用单个换行符--这是由regex_newline.Replace(.)决定的。打电话,但你没出现。
所以基本上,答案是
Regex regex_newline = new Regex("(\r\n|\r|\n)"); // remove the '+'
// :
regex_newline.replace(somestring, "X");发布于 2013-01-26 20:23:11
只需使用String.Replace方法并替换字符串中的Environment.NewLine。不需要Regex。
http://msdn.microsoft.com/en-us/library/system.environment.newline.aspx
https://stackoverflow.com/questions/14541202
复制相似问题