Sinoy Devassy Sinoy Devassy - 1 month ago 5x
ASP.NET (C#) Question

Split and get last part of a string in c#

I have string like "abc-def-gef". I need to remove the first part of the string from "-" and get the last part like "def-gef". How its possible in c#. Please help me to find out the solution.

Thank you.



string str = "abc-def-gef";
str = str.Substring(str.IndexOf("-")+1);

IndexOf("-") will return the index of the first "-" and Substring will cut the string from that index (+1 to skip "-") to the end of the string