C# 当中间出现较多时,获取长度为10的两个字符串之间的字符串
我希望在C# 当中间出现较多时,获取长度为10的两个字符串之间的字符串,c#,C#,我希望在之间有一个长度为10的子字符串,例如 发票编号:
之间有一个长度为10
的子字符串,例如
发票编号:<12345sd)
请注意,字符串可以包含许多,请尝试使用正则表达式:
到目前为止你试过什么?。。。因此,投票结束一个质量太低的问题,因为你的问题不清楚,请举更多的例子。你说的更多是什么意思
String source = "Invoice No:< 12345sd ) <1234567890>";
// {10} 10 characters exactly
// {10,} 10 characters or more
// {,10} 10 characters or few
// {5,10} from 5 up to 10 characters
var matches = Regex
.Matches(source, @"<([^<]{10})>")
.OfType<Match>()
.Select(match => match.Groups[1].Value)
.ToArray(); // Or FirstOrDefault(); if you want just 1st match
// 1234567890
Console.Write(string.Join(", ", matches));