string var = "a231cc"; byte[] dat = System.Text.Encoding.Default.GetBytes(var); string number = ""; foreach (byte b in dat) { if (b > 47 && b < 58) { number = number + (char)b; } }
string a="a231cc 123"提取123出来
string a ="a123cc"; string bb =String.Empty; byte[] _b = System.Text.Encoding.ASCII.GetBytes(a); foreach(byte b in _b) { if (b>47 && b<58) { bb = bb+(char)b; } } Console.WriteLine(bb);
byte[] dat = System.Text.Encoding.Default.GetBytes(var);
string number = "";
foreach (byte b in dat)
{
if (b > 47 && b < 58)
{
number = number + (char)b;
}
}
string bb =String.Empty;
byte[] _b = System.Text.Encoding.ASCII.GetBytes(a);
foreach(byte b in _b)
{
if (b>47 && b<58)
{
bb = bb+(char)b;
}
}
Console.WriteLine(bb);
中间有空格,用分割!string a="a231cc 123";
string str;
string[] strs=a.split(' ');
str=strs[1].tostring();
string str = "a231cc 123";
MatchCollection mc = Regex.Matches(str, @"[0-9]+");
Console.WriteLine(mc[mc.Count-1].ToString());
/*
123
请按任意键继续. . .
*/
string test = "a231cc 123";
Match m = Regex.Match(test, @"(?<=\s)(\d+)(?=[^0-9]?)", RegexOptions.IgnoreCase);
if (m.Success) Response.Write(m.Value);