C# 获得字符串中多个相同字符某个字符的位置??如何?急急急!!!

来源:百度知道 编辑:UC知道 时间:2024/05/31 12:43:36
如题:
wordFilePath = D:\wwwroot\ReadWordToXml\ReadWordToXml\bin\Debug
我要直接获得倒数第二个“\”的位置。请教高手。

string wordFilePath = @"D:\wwwroot\ReadWordToXml\ReadWordToXml\bin\Debug";
int b = wordFilePath .LastIndexOf(@"\"); //首先获得最后一个‘\’的位置
string wordFilePath1 = wordFilePath1.Substring(0, b); //截取最后一个‘\’前的字符串,得到“D:\wwwroot\ReadWordToXml\ReadWordToXml\bin”

wordFilePath1 .LastIndexOf(@"\"); //获取wordFilePath1 的最后一个‘\’的位置,也就是你要的第二个‘\’的位置,是38对吧,哈哈

wordFilePath=wordFilePath.SubString(0,wordFilePath.LastIndexOf("\")-1);
wordFilePath=wordFilePath.SubString(wordFilePath.LastIndexOf("\")+1);

string s = @"c:\ii\iii\iiiii\";
int k = s.LastIndexOf('\\', s.LastIndexOf('\\') - 1);