本文介绍了如何获取lastindexof string only text的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果实际的文件夹名称未知,那我怎么才能得到这个例子中的最后一个索引文本只得到Sub2?

\\Sub1 \\Sub2 \\



在这个例子中

\\Sub1 \\Sub2 \\Sub3 \\

只获得Sub3?

If the actual folder names are unknown how could i then only get the last index text in this example only get Sub2?
\\Sub1\\Sub2\\

In this example
\\Sub1\\Sub2\\Sub3\\
Only get Sub3 ?

推荐答案

string str = @"\sub1\sub2\sub3";
string dirName = new DirectoryInfo(str).Name;



ref。

[]

[]


string str = @"\sub1\sub2\sub3";
var x = str.LastIndexOf('\\');
Console.WriteLine(str.Substring(x + 1, str.Length - x - 1));


string[] s = "\\Sub1\\Sub2\\Sub3\\".Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);





然后你想要的字符串将在



Then your desired string would be in

s[s.Length - 1];


这篇关于如何获取lastindexof string only text的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 22:40