简体   繁体   English

替换特殊字符或特殊字符后跟空格

[英]Replace special characters or special characters followed by space

I have this particular string:我有这个特殊的字符串:

Administrationsomkostninger                           I              -2.889         - r0.l l0

I would like to replace these characters:r,l and i with 1. I use this expression:我想用 1 替换这些字符:r、l 和 i。我使用这个表达式:

([(t|r|l|i|)])

That gives me this string:这给了我这个字符串:

Adm1n1s11a11onsomkos1n1nge1                           1              -2.889         - 10.1 10 

Now i want to replace the all digits that contains a digit followed + a whitespace现在我想替换包含一个数字后跟一个空格的所有数字

so in this case only - 10.1 10 gets converted to -10.110所以在这种情况下只有- 10.1 10被转换为-10.110

Try this尝试这个

            string input = "Administrationsomkostninger                           I              -2.889         - r0.l l0";
            string pattern = @"(?'spaces'\s){2,}";
            string output = Regex.Replace(input, pattern, " ");
​

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM