str1="1→2";
str2="1→2→22→33";
str3="1→2→33→45→253";
如上所述,字符串的最后一个“→”后的位数不定,怎样取得最后一个“→”后的数字。
str1取得数字2
str2取得数字33
str3取得数字253
str2="1→2→22→33";
str3="1→2→33→45→253";
如上所述,字符串的最后一个“→”后的位数不定,怎样取得最后一个“→”后的数字。
str1取得数字2
str2取得数字33
str3取得数字253
string s_num=s[s.length-1];
string result = "";
Match m = Regex.Match(yourStr, @"→(?<num>\d+)$");
if (m.Success)
{
result = m.Groups["num"].Value;
}
string result = str3.Substring(str3.LastIndexOf("→")+1);
string result = "";
Match m = Regex.Match(yourStr, @"\d+$");
if (m.Success)
{
result = m.Value;
}\d+$
$ 与字符串结束的地方匹配,不匹配任何字符
\d+ 匹配一个或多个数字
放在一起就是结尾处的数字
int pos = str.LastIndexOf("→");
if(pos > 0)
{
int result = Convert.ToInt32(str.Substring(pos));
}
int result = Convert.ToInt32(str.Substring(pos + 1));