Fast and clever way to get the NON FIRST segment of a C# string

前端 未结 6 2393
太阳男子
太阳男子 2021-02-18 21:22

I do a split(\' \') over an string and I want to pull the first element of the returned string in order to get the rest of the string.

f.e. \"THIS IS

6条回答
  •  轮回少年
    2021-02-18 21:50

    Try this

      string str = "THIS IS AN AMAZING STRING";
      string firstString = str.Split(' ')[0];  //get the first string
      string newStr = str.Replace(firstString + " ", "");  //remove the first string
    
      //OR
    
      string newStr = str.Remove(0, firstString.Length + 1);
    

提交回复
热议问题