我有這樣的漫畫字符串。C#WPF從字符串中分離字符(從後面開始)
www.asdsad.de/dsfdsf/sdfdsf=dsfdsfs?dsfsndfsajdn=sfdjasdhads= test.xlsx
我想只得到test.xlsx出來。 所以我想說我想把背後的字符串分開。 他他曾經是第一個=符號找到我的字符串提供從末尾到=符號去。
最好的辦法是做什麼?
不幸的是,我不知道如何處理SubString,因爲長度總是可以不同。但我知道,到底是什麼,我需要和與第一=不必要開始從後面
我有這樣的漫畫字符串。C#WPF從字符串中分離字符(從後面開始)
www.asdsad.de/dsfdsf/sdfdsf=dsfdsfs?dsfsndfsajdn=sfdjasdhads= test.xlsx
我想只得到test.xlsx出來。 所以我想說我想把背後的字符串分開。 他他曾經是第一個=符號找到我的字符串提供從末尾到=符號去。
最好的辦法是做什麼?
不幸的是,我不知道如何處理SubString,因爲長度總是可以不同。但我知道,到底是什麼,我需要和與第一=不必要開始從後面
是,Substring
會做,而且也沒有必要知道長度:
string source = "www.asdsad.de/dsfdsf/sdfdsf=dsfdsfs?dsfsndfsajdn=sfdjasdhads=test.xlsx";
// starting from the last '=' up to the end of the string
string result = source.SubString(source.LastIndexOf("=") + 1);
另一種選擇:
string source = "www.asdsad.de/dsfdsf/sdfdsf=dsfdsfs?dsfsndfsajdn=sfdjasdhads=test.xlsx";
Stack<char> sb = new Stack<char>();
for (var i = source.Length - 1; i > 0; i--)
{
if (source[i] == '=')
{
break;
}
sb.Push(source[i]);
}
var result = string.Concat(sb.ToArray());
yourString.Substring(yourString.LastIndexOf('=')+ 1); – Evk