Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get everything after a certain index in string c#

Tags:

string

c#

.net

Lets say I have the string:

"MyNamespace.SubNameSpace.MyClassName"

How do I extract just everything after the last period, "MyClassName"

like image 714
y2k Avatar asked Mar 30 '10 06:03

y2k


1 Answers

Use String.Substring and String.LastIndexOf methods.

string str = "MyNamespace.SubNameSpace.MyClassName";
string str1 = str.Substring(str.LastIndexOf('.') + 1);
like image 125
rahul Avatar answered Sep 28 '22 07:09

rahul