我有一个字符串,我想操纵。问题是替换包含正则表达式。正则表达式:“替换”模式
var result = Regex.Replace("Abc", "\r\nAbc\r\n", "\r\n");
// or something like that, it can be also \t and so on...
但结果不是新行,而是字符串“\ r \ n”。
PS:顺便说一下,如果我想以取代无中生有,因为很简单的例子:
Regex.Replace("abc", "abc", "")
正则表达式似乎失败。不能将字符串替换为空字符串?
\ r \ n是一个新行(返程+换行),其在某些操作系统中使用系统。 – Goran
如果你想用空字符串替换字符串,只需使用String.Replace()':'string result =“abc”.Replace(“abc”,“”);' – bump
请看我的回答@Crud – peter70