Extract two substrings from a string

前端 未结 1 985
心在旅途
心在旅途 2021-01-29 14:13

what is the best and optimise wayto extract substrings from a specified string.

my primary string is like

string str = \"ACK         


        
1条回答
  •  逝去的感伤
    2021-01-29 14:46

    string str = @"ACKAAA0BBBB1";
    var matches = Regex.Matches(str, @"(\w+)<\/t>");
    
    Console.WriteLine(matches[1].Groups[1]);    // outputs "AAAA1"
    Console.WriteLine(matches[2].Groups[1]);    // outputs "BBB2"
    

    This assumes that your data are always inside a tag, also you might want to do some error catching in case no matches are found.

    0 讨论(0)
提交回复
热议问题