c# - 从字符串中获取第二次出现

标签 c# asp.net

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/

相关文章:

c# - 在其他控件上方显示透明加载微调器

c# - 互联网上的企业数据

c# - ListView 无法使用 Xamarin Forms 正确呈现

javascript - 从 Javascript 分配 Session 变量

c# - Timespan 输入字符串的格式不正确

c# - Farseer:对象不会从静态对象弹回

c# - 单元测试使用静态变量的 C#/.NET 类(单元测试进程隔离)

asp.net - ASP .NET 中表单的输入元素名称

asp.net - 空白密码难题

asp.net - 如何使用 IIS 授予 IIS APPPOOL\DefaultAppPool 对 Asp.net 中存储过程的访问权限?