Get string between two strings in a string

前端 未结 23 2395
别跟我提以往
别跟我提以往 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条回答
  •  攒了一身酷
    2020-11-22 10:41

    In C# 8.0 and above, you can use the range operator .. as in

    var s = "header-THE_TARGET_STRING.7z";
    var from = s.IndexOf("-") + "-".Length;
    var to = s.IndexOf(".7z");
    var versionString = s[from..to];  // THE_TARGET_STRING
    

    See documentation for details.

提交回复
热议问题