I have such a comic string.
我有这样一个漫画字符串。
www.asdsad.de/dsfdsf/sdfdsf=dsfdsfs?dsfsndfsajdn=sfdjasdhads=test.xlsx
www.asdsad.de/dsfdsf/sdfdsf=dsfdsfs?dsfsndfsajdn=sfdjasdhads=test.xlsx
I would like to get only the test.xlsx out. So I wanted to say that I wanted to separate the string from behind. That he he once the first = sign found me the string supplies the from the end to the = sign goes.
我想只得到test.xlsx。所以我想说我想将字符串从后面分开。他曾经是第一个=符号发现我字符串从最后提供给=符号。
Whats the best way to do this?
什么是最好的方法呢?
Unfortunately, I would not know how I should do with SubString, since the length can always be different. But I know that in the end is what I need and the unnecessary with the first = Begin from behind
不幸的是,我不知道如何处理SubString,因为长度总是不同的。但我知道到底是我需要的东西和第一个不必要的东西=从后面开始
2 个解决方案
#1
2
Yes, Substring
will do, and there's no need to know the length:
是的,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);
#2
1
Another option:
另外一个选择:
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());
#1
2
Yes, Substring
will do, and there's no need to know the length:
是的,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);
#2
1
Another option:
另外一个选择:
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());