Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split string by last separator

Tags:

c#

What I have is a giant text file that contains a bunch of strings that are split by \. The problem for me is there can be 5 \ or 4 \ or 3 \.

What I need to to pull the last \ no matter how many of them there are. Any help is appreciated.

Examples:

I\need\this
I\want\line\this
Hello\give\me\all\this

I need the word this for example, but obviously it's not just the word this.


1 Answers

string last = inputString.Substring(inputString.LastIndexOf('\\') + 1);
like image 114
Matthew Abbott Avatar answered Sep 14 '25 05:09

Matthew Abbott