c#检查字符串是否为数字

该日志由 samool 发表于 2007-12-28 10:01 AM

正则表达
   string regex = @^\d+$;

  自己写个方法吧:这是我写的.
          private bool isNumber(string s)
   {
    int Flag = 0;
    char[]str = s.ToCharArray();
    for(int i = 0;i < str.Length ;i++)
    {
     if (Char.IsNumber(str[i]))
    {
     Flag++;
    }
   else
   {
    Flag = -1;
    break;
   }
  }
  if ( Flag > 0 )
  {
   return true;
  }
  else
  {
   return false;
  }
          }

测试
                   private void Button1_Click(object sender, System.EventArgs e)
  {
   if (isNumber(TextBox1.Text.Trim()))
   {
    TextBox2.Text = 是数字;
   }
   else
   {
    TextBox2.Text = 不是数字;
   }
  }

 

try
{
 double.Parse(this.TextBox1.Text);
 Response.Write(是数字);
}
catch
{
 Response.Write(不是数字);
}

或者用正则表达式也可以:
using System.Text.RegularExpressions;
------------------------
Regex r=new Regex(@^\d+(\.)?\d*$);
if(r.IsMatch(this.TextBox1.Text))
{
 this.Response.Write(是数字);
}
else
{
 this.Response.Write(不是数字);
}

public static bool StrIsInt(string Str)
    {
      try
      {
        Int32.Parse(Str);
        return true;
      }
      catch
      {
        bool flag = false;
        return flag;
      }
    }

 

应该使用正则表达式:
string pattern = @^\d+(\.\d)?$;
if(Text1.Text.Trim()!=)
{
if(!Regex.IsMatch(sign_money.Text.Trim(),pattern))
{
   Text1不是数字;
}
else
{
  Text1是数字;
}
}

该日志标签: .net, 字符串, 数字

VB6如何访问.NET WebService服务

该日志由 samool 发表于 2007-10-18 4:53 PM

首先安装Microsoft SoapToolkit,因为VB自身不支持WebService,需要安装SoapTookit后能调用WebService。

下载SoapTookit3.0

然后在VB6中点菜单“工程”—“引用”-把“Microsoft Soap Type Libray v3.0” 打上钩就可以了。

     Dim mysoap As New SoapClient30
     mysoap.MSSoapInit ("http://www.samool.com/soap/Webservice.asmx?WSDL")
     Label1.Caption = mysoap.helloWorld(Text1.Text)

按上面方法直接调用WebService函数就OK了。

该日志标签: vb6, .net, webservice, soaptoolkit, soapclient

Working with .NET data in Delphi

该日志由 samool 发表于 2007-06-24 12:29 PM

Webservices offer a rich world of functionality. This world is available to the Delphi programmer with the introduction of the Webservice importer introduced in Delphi 6, with version 6.02 also available in Delphi pro. A webservice can work with pretty complex data, with .NET it is a snap to return and  receive complete XML datasets. Delphi does not know how to work with these datasets natively. In this paper I will show how to work with .NET data using the GekkoDotNetDataset componenet.

» 阅读该日志全文...

该日志标签: .net, delphi, dataset

delphi如何调用.NET webservice

该日志由 samool 发表于 2007-01-11 9:03 AM

假设您已经在.net上建立了自己的webservice,目前只是想在delphi上实现对net上自己的webservice 接口的调用

1)  在你的工程中 new  -> other 选择 webservices 这页

2)  选择其中的 wsdl importer 项

3)  在其中的wsdl source中填入你已经知道的wdsl地址,这里我填入我的地址是
http://192.168.0.123/hello/tijiaosj.asmx?wsdl

4) next后 就自动生成了一个unit

5)  这个unit中包含了你提供的url地址中的所有可用接口
其中 GetXXXXXSoap 这个函数返回了这些接口的class
在业务代码中只要写 GetXXXXXSoap.XXXfunction就可以了

6)  另外提当函数要操作中文的时候,记得修改GetXXXXXSoap,添加这条语句
RIO.HTTPWebNode.UseUTF8InHeader := True; //解决中文乱码问题
呵呵,很简单,对吧

最后,稍微改了一下Delphi生成的接口单元

改动的地方为:

7). 添加接口的执行选项默认为 ioDocument
如果是JAVA 接口, 将执行选项改为 ioLiteral  即可.

修改后的代码如下:
InvRegistry.RegisterInvokeOptions(TypeInfo(XcdsExPortType), ioDocument);

该日志标签: delphi, webservice, .net