如何提取此子字符串" 60684"从这个字符串" / fa / Viewer / Switcher / 60684/0"在c#?
答案 0 :(得分:0)
您可以使用Split
方法:
string str = "/fa/12012/Switcher/60684/0";
string str2 = str.Split('/')[4];
答案 1 :(得分:0)
一种方法是使用正则表达式:
static void Main()
{
string pattern = @"\/[a-zA-Z]+\/[a-zA-Z]+\/[a-zA-Z]+\/([0-9]+)\/[a-z0-9]+";
var regex = new Regex(pattern);
string path = "/fa/Viewer/Switcher/60684/0";
var match = regex.Match(path);
Console.WriteLine(match.Groups[1].ToString());
}
答案 2 :(得分:-1)
像这样:
string url = @"/fa/12012/Switcher/60684/0";
string[] NumberAfterSwitcher = url.Split('/');
string num = (NumberAfterSwitcher.Length > 3) ? (String)url.Split('/').GetValue(3) : String.Empty;