开发者

Split string by last separator

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 开发者_Python百科word this.


string last = inputString.Substring(inputString.LastIndexOf('\\') + 1);


string myString = inputString.Split('\\').Last();


Almost forgot this one (although it's a bit cheeky):

string result = Path.GetFilename(input);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜