我想在string 中取出所有的数字
例如
string tt="1a2s3d4f5g6h7q8你";最后取得结果是 tt=12345678如何实现???
例如
string tt="1a2s3d4f5g6h7q8你";最后取得结果是 tt=12345678如何实现???
解决方案 »
- 【求助】很简单的功能,说起来很费劲,4小时没解决
- C#像千千静听一样头部滚动
- 請教高手. 如何增加 ListBox.Items.屬性
- 求C#生成图片的源码
- 一个SQL server统计问题
- 相同类名,不同namespace名的webservice调用的问题。(请教有分布式webservice经验的高手)
- SQLSERVER2005 新建维护计划保存时出错
- 哪位高手给个 IL编译器 多谢
- .net中radio控件问题
- 调用更新数据库记录的存储过程,但数据库记录却不更新
- 初学,使用DataReder,为什么只能使用其中一个显示,要么就是DataGrid能显示,要么就是TextBox1显示数据
- 高分请教用户控件,在线等。。。。。。
{
string str=string.substring(i-1,i);
switch(str)
{
case "1":
tt+=str;
breack;
case "2":
tt+=str;
breack;
...
..
}
}
tt.indexof(i)属于数字
s=s + tt.indexof(i) s是目标字串。
岂不要累死。
System.Text.StringBuilder sb=new System.Text.StringBuilder();
for(int i=0;i<tt.Length;i++)
{
if(tt[i]>=48 && tt[i]<=57 || tt[i]=='.')
{
sb.Append(tt[i]);
}
}
MessageBox.Show(sb.ToString());你可以添加一个标记变量判断已经添加了一个小数点号.
using System.Text.RegularExpressions ;namespace ConsoleApplication6
{
/// <summary>
/// Class1 概要説明
/// </summary>
class Class1
{
/// <summary>
///
/// </summary>
[STAThread]
static void Main(string[] args)
{
string temp ="1fy75m02j9";
string biaozhun=@"[^0-9]";
temp=Regex.Replace(temp,biaozhun,"");
System.Console.WriteLine(temp);
}
}
}