[英]Get second occurrence from a string
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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.