Get string between two strings in a string

前端 未结 23 2211
别跟我提以往
别跟我提以往 2020-11-22 09:46

I have a string like:

\"super exemple of string key : text I want to keep - end of my string\"

I want to just keep the string which is betw

23条回答
  •  -上瘾入骨i
    2020-11-22 10:47

    string input = "super exemple of string key : text I want to keep - end of my string";
    var match = Regex.Match(input, @"key : (.+?)-").Groups[1].Value;
    

    or with just string operations

    var start = input.IndexOf("key : ") + 6;
    var match2 = input.Substring(start, input.IndexOf("-") - start);
    

提交回复
热议问题