遍历:
参考:
public bool JudgeFigure(string str)
{
if(str.Trim().Length<=0)
return true;
int dot=0;
if(str[0]=='.'||str[str.Length-1]=='.')
return false;
for(int i=0;i<str.Length;i++)
{
if(dot>1) return false;
if(Char.IsDigit(str,i))
{
continue;
}
if(str[i]=='.')
{
dot=dot+1;
continue;
}
return false;
}
return true;
}

解决方案 »

  1.   

    如果只有第一个是字母,后面都是数字,有没有更简单一点的方法?
    那如果我要把截取出来的数字转换成int型,要怎么转呢?
      

  2.   

    string str = "a1234";
    int i = Convert.ToInt32(str.Substring(1, str.Length - 1));
      

  3.   

    string s = "a1b2c3d45sdfegtr234";
     System.Text.RegularExpressions.Regex rgx =New System.Text.RegularExpressions.Regex("[a-zA-Z][0-9]{1,}");
     System.Text.RegularExpressions.MatchCollection match = rgx.Matches(s);
     foreach(System.Text.RegularExpressions.Match m in match)
    {
         Console.WriteLine(rgx.Match(m.Value, "[0-9]{1,}$").Value);
    }  
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
      

  4.   

    string test = "c789";
                int i;
                int.TryParse(test.Remove(0, 1), out i);
                Console.WriteLine(i);如果字母位置及位数不定,用正则简单一些
      

  5.   

    摘录:《程序员秘书》--源代码--字符、字符串、文本--常见正则表达式
    8、在Form1.cs的视图设计器中,选中button3,在属性框中选中事件,双击Click,在Form1.cs的代码设计器中,添加修改如下代码
    private void button3_Click(object sender, EventArgs e)
    {
        MatchCollection MC = Regex.Matches("sd23jk4k<3k3424kkl[l242", @"(\d+\.?\d*|\.\d+)");
        string Str = "";
        for (int i = 0; i < MC.Count; i++)
            Str += MC[i].Value;
        MessageBox.Show(this, "提取到的数字:" + Str, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }立即成为编程经验丰富的程序员不是梦,详见:http://www.psec.net.cn