Sinoy Devassy Sinoy Devassy - 1 year ago 133
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.

Answer Source


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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download