简体   繁体   English

如何在C#中用空字符替换数字字符?

[英]How to replace a numeric character with empty character in C#?

I have string like 我有像

  1 69 / EMP1094467 EMP1094467 :  2 69 / ScreenLysP 

here the numeric characters should be replace with empty characters, Llike: 在这里,数字字符应替换为空字符Llike:

/ EMP1094467

I tried like this 我尝试过这样

var output = Regex.Replace(input, @"[\d-]", string.Empty);

which produced the following result: 产生了以下结果:

/ EMP

Please suggest a better solution. 请提出更好的解决方案。

string.Substring seems fitting here: string.Substring在这里似乎很合适:

var str = "1 69 / EMP1094467";
var result = str.Substring(str.IndexOf("/")); // "/ EMP1094467"

You can try using word boundaries: 您可以尝试使用单词边界:

var input = "1 69 / EMP1094467 EMP1094467 :  2 69 / ScreenLysP ";
var output = Regex.Replace(input, @"\b[\d]+\b", string.Empty);

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

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