Reputation: 31
I am trying to get a part of an string in C#
My string is:
svn://mcdssrv/repos/currecnt/class/MBackingBean.java
and I want this part of string:
svn://mcdssrv/repos/currecnt/class/
How can I get the above?
Upvotes: 0
Views: 130
Reputation: 59292
Do this with String.Remove()
string s = "svn://mcdssrv/repos/currecnt/class/MBackingBean.java";
Console.WriteLine(s.Remove(s.LastIndexOf('/'))+"/");
Upvotes: 1
Reputation: 12807
One more way to do that:
string str = "svn://mcdssrv/repos/currecnt/class/MBackingBean.java";
string s = Regex.Match(str, ".*/").Value;
Upvotes: 1
Reputation: 9862
Try this with String.Substring:
string str = "svn://mcdssrv/repos/currecnt/class/MBackingBean.java";
str = str.Substring(0,str.LastIndexOf('/')+1);
Upvotes: 2