user175084 user175084 - 1 year ago 88
C# Question

remove last word in label split by \

Ok i have a string where i want to remove the last word split by \

for example:

string name ="kak\kdk\dd\ddew\cxz\"

now i want to remove the last word so that i get a new value for name as

name= "kak\kdk\dd\ddew\"

is there an easy way to do this


Answer Source

How do you get this string in the first place? I assume you know that '\' is the escape character in C#. However, you should get far by using

name = name.TrimEnd('\\')
name = name.Remove(name.LastIndexOf('\\') + 1);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download