简体   繁体   English

使用 c# 在合并值中拆分并获取字符串后的值

[英]split and get value after string in consolidated value using c#

I want to get the value from the List<string> which contains different format as below.我想从包含不同格式的List<string>获取值,如下所示。

Formats:格式:

var fieldValue =  { 
      "00 1234567 89 EXT 098", 
      "001 234 56 789 EX 0987",  
      "0 0123456789 EXTEN 09",
      "00123456789 EXTENSION0987",
      "00123456789E098987" 
}

Among all these values, I want to get the value ('098', '0987', '09', '0987', '098987') after string such as 'EXT', 'EX', 'EXTEN', 'EXTENSION', 'E'在所有这些值中,我想在诸如'EXT'、'EX'、'EXTEN'、'EXTENSION 之类的字符串之后获取值('098', '0987', '09', '0987', '098987') ', 'E'

The string may be differ in each value, so that I confused to apply condition to get the values after that.每个值中的字符串可能不同,所以我很困惑应用条件来获取之后的值。

Also I am unable to split this using <space> since it may contain in some values.此外,我无法使用<space>拆分它,因为它可能包含某些值。

Please advice me to get the required values.请建议我获得所需的值。 Thanks in advance,提前致谢,

We can try doing a regex replacement on ^.*?(?=\\d+$) and replace with empty string:我们可以尝试对^.*?(?=\\d+$)进行正则表达式替换并替换为空字符串:

string input = "00123456789E098987";
string output = Regex.Replace(input, "^.*?(?=\\d+$)", "");
Console.WriteLine(input);
Console.WriteLine(output);

This prints:这打印:

00123456789E098987
098987

Note: In the case of an input which does not end in at least one digit, the above logic would just return that original input.注意:对于不以至少一位数字结尾的输入,上述逻辑只会返回原始输入。 Ie 123ABC remains as that.123ABC保持不变。

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

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