[Solved] Get String between two strings with length 10 when you have more occurance of inbetween [closed]


Try using regular expressions:

  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

Test

  // 1234567890
  Console.Write(string.Join(", ", matches));

solved Get String between two strings with length 10 when you have more occurance of inbetween [closed]