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

前端 未结 6 2185
太阳男子
太阳男子 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:58

    Very simply, you could do:

    string input = "THIS IS AN AMAZING STRING";
    string result = input.Substring(input.IndexOf(' ') + 1);
    

    This will work for the type of input you're specifying (where there is always a space between the first two words in your string), but for case where the input string does not have spaces at all, it returns the whole string as-is.

提交回复
热议问题