C# 字符串操作
时间:2011-05-01 来源:李豫川
从字符串:aba,3456df3!344dfdf 提取 34563344
暂时就想到这几种方法,以后有了再补充
引用:using System.Diagnostics;
Stopwatch sp = new Stopwatch();
sp.Start();
string str= "aba,3456df3!344dfdf";
string result = string.Empty;
//测试结果 34563344 用时 00:00:00.0000094
for (int i = 0; i < str.Length; i++)
{
if (char.IsNumber(str[i]))
{
result += str[i];
}
}
////测试结果 34563344 运行时间 00:00:00.0000081
//foreach (char strString in str.ToCharArray(0, str.Length - 1))
//{
// if (char.IsNumber(strString))
// {
// result += strString;
// }
//}
////测试结果 34563344 运行时间 00:00:00.0000030
//result = str.Substring(4, 4) + str.Substring(10, 1) + str.Substring(12, 3);
// 测试结果 34563344 运行时间 00:00:00.0000726
//result = Regex.Replace(str, @"[^\d+]", "");
sp.Stop();
HttpContext.Current.Response.Write(result +"<br/>"+ sp.Elapsed);
- 系统休眠文件删除后果 如何删除计算机的休眠文件 2025-04-22
- 站群服务器是什么意思 站群服务器的作用 站群服务器和普通服务器的区别 2025-04-22
- jQuery插件有何作用 jQuery插件的使用方法 2025-04-22
- jQuery插件有哪些种类 简单的jQuery插件实例 2025-04-22
-