最后一个斜杠后获取内容 [英] Get contents after last slash

查看:57
本文介绍了最后一个斜杠后获取内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下格式目录的字符串:

I have strings that have a directory in the following format:

C://hello//world

我如何提取最后一个/字符( world )之后的所有内容?

How would I extract everything after the last / character (world)?

推荐答案

string path = "C://hello//world";
int pos = path.LastIndexOf("/") + 1;
Console.WriteLine(path.Substring(pos, path.Length - pos)); // prints "world"

LastIndexOf 方法的作用与 IndexOf ..相同,但从字符串的末尾开始.

The LastIndexOf method performs the same as IndexOf.. but from the end of the string.

这篇关于最后一个斜杠后获取内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆