Home > Mobile >  Get text after first occurrence of a Character
Get text after first occurrence of a Character

Time:10-12

I'm making a win form app in visual studio, and I need to get the text after a comma, or any character if possible, I've been using line.Split(',').Last();, however I believe this should return an array if you have more than one comma, and would break my code if the string line, were to have more than one comma, I would like to get all text after the first comma. Thanks.

PS: I want everything after the first occurrence, so after the first usage of the character, any other comma's in the string shouldn't matter.

Example: String line = a,b,a If I use line.Split(',').Last(); it should return an array, but I want one string, I want it to return b,a

CodePudding user response:

You should use: line.SubString(line.IndexOf(","));

line : "abc,dfghi,jk,lmn" return is : ",dfghi,jk,lmn";

if you don't want first comma use line.Substring(line.IndexOf(",")).Remove(0, 1);

  •  Tags:  
  • c#
  • Related