string strTemp = "123456公里";
char[] cStr = new Char[]{'0','1','2','3','4','5','6','7','8','9'};
MessageBox.Show(strTemp.Substring(0,strTemp.LastIndexOfAny(cStr)+1));
char[] cStr = new Char[]{'0','1','2','3','4','5','6','7','8','9'};
MessageBox.Show(strTemp.Substring(0,strTemp.LastIndexOfAny(cStr)+1));
as follows: using System.Text.RegularExpressions; //正则表达式
...... string st="123456公里"; Match ma=Regex.Match(st,@"[0-9]+");
if(ma.Success)
{
str=ma.Value; //str="123456"
} 如果要汉字:
string st="123456公里"; Match ma=Regex.Match(st,@"[\u4e00-\u9fa5]+");
if(ma.Success)
{
str=ma.Value; //str="公里"
}