string formatting

S

soup_nazi

I have a one string per line and I want to delete the last part of each
string after and including the final "/" character for each line



For example:



Applications/base/test1
Applications/base/test1/test2
Applications/base/test1/test2/test3
Applications/base/test1/test2/test3/test4



After the deletion would equal



Applications/base
Applications/base/test1
Applications/base/test1/test2
Applications/base/test1/test2/test3



Any ideas?



I was think of counting the number of "/" characters in each line
and then deleting the text after the n - 1 character. Or something
like that but I didn't know if there was an easier way.
 
R

rossum

I have a one string per line and I want to delete the last part of each
string after and including the final "/" character for each line



For example:



Applications/base/test1
Applications/base/test1/test2
Applications/base/test1/test2/test3
Applications/base/test1/test2/test3/test4



After the deletion would equal



Applications/base
Applications/base/test1
Applications/base/test1/test2
Applications/base/test1/test2/test3



Any ideas?



I was think of counting the number of "/" characters in each line
and then deleting the text after the n - 1 character. Or something
like that but I didn't know if there was an easier way.

myString.LastIndexOf() will tell you where the last '/' is.

myString.Substring() will extract the piece of the string that you
want.

rossum
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top