Get string between two strings in a string

前端 未结 23 2409
别跟我提以往
别跟我提以往 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:26

    If you are looking for a 1 line solution, this is it:

    s.Substring(s.IndexOf("eT") + "eT".Length).Split("97".ToCharArray()).First()
    

    The whole 1 line solution, with System.Linq:

    using System;
    using System.Linq;
    
    class OneLiner
    {
        static void Main()
        {
            string s = "TextHereTisImortant973End"; //Between "eT" and "97"
            Console.WriteLine(s.Substring(s.IndexOf("eT") + "eT".Length)
                               .Split("97".ToCharArray()).First());
        }
    }
    

提交回复
热议问题