string str="Customer was charged £10,000 and £11,000 for the same service in June and July respectively".
我想从字符串中获取第二个金额。
我使用下面的表达式,但它只给出第一个值,即 10,000 英镑。
string m = Regex.Match(str, @"\£[^ ]+").Value.ToString();
请告诉我如何跳过第一个并直接选择第二个值。
最佳答案
使用 Matches()
获取所有可能的结果,使用 Skip(1)
跳过第一个
string str = "Customer was charged £10,000 and £11,000 for the same service in June and July respectively";
string m = Regex.Matches(str, @"\£[^ ]+").Cast<Match>().Skip(1).FirstOrDefault()?.Value?.ToString();
关于c# - 从字符串中获取第二次出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52817274/