比如
string st1 = "124"
string st2 = "asdf";
string st3 = "sdf13";
自动判断出 st1 可以转换成数字形式 int i1 = Convert.int32(st1);
st2 和st3 无法转换成数字形式如果做出判断呢
string st1 = "124"
string st2 = "asdf";
string st3 = "sdf13";
自动判断出 st1 可以转换成数字形式 int i1 = Convert.int32(st1);
st2 和st3 无法转换成数字形式如果做出判断呢
解决方案 »
- 找不到Stream.CopyTo()方法
- 坛里有位朋友老是因为编码和程序问题我和争论,大家进来看看
- imagelist图片显示大小问题
- 一个窗体加载的问题
- 求可控制内容的在屏幕右下角弹出一个提示框的解决方案
- 急问 C#怎么调用的 lib库啊
- vs 2005 界面变样了,设计与实际不同
- 用网页打开EXCEL,WORD,PPT等文档 C# asp.net
- 使用StringIntObject给Combox添加值的问题??
- devexpress的ComboxEdit如何设置为不能编辑?也就是只读
- C++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 急求!!!请问用 c# 写 PocketPC 程序的时候如何执行一个外部程序?
try {
FoundMatch = Regex.IsMatch(SubjectString, "^\\d+$");
} catch (ArgumentException ex) {
// Syntax error in the regular expression
}
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text.RegularExpressions;namespace TestApp
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null; public Form1()
{
InitializeComponent();
} protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(96, 80);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 184);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(256, 23);
this.label1.TabIndex = 1;
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// button1
//
this.button1.Location = new System.Drawing.Point(112, 128);
this.button1.Name = "button1";
this.button1.TabIndex = 2;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button1);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion [STAThread]
static void Main()
{
Application.Run(new Form1());
} private void button1_Click(object sender, System.EventArgs e)
{
bool FoundMatch = false;
try
{
FoundMatch = Regex.IsMatch(this.textBox1.Text, "^\\d+$");
}
catch (ArgumentException ex)
{
// Syntax error in the regular expression
}
this.label1.Text=FoundMatch?"能转化为整数":"不能转化为整数";
}
}
}测试通过
public static bool IsNumber(string str)
{
System.Text.RegularExpressions.Regex regex=new Regex(REGEXP_IS_VALID_INT);
if(regex.IsMatch(str))
return true;
else
return false;
}