.Net常用技巧_字符串检查与判断

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace MyUtility
{
    /// <summary>
    ///
    /// </summary>
    public class IsNumber
    {
        /// <summary>
        /// 判断字符串是否为整数字符串
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public bool isNumber(String message)
        {
            Regex rex = new Regex(@"^\d+$");
            if (rex.IsMatch(message))
                return true;
            else
                return false;
        }

        /// <summary>
        /// 判断字符串是否为指定长度的整数字符串
        /// </summary>
        /// <param name="message"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public bool isNumber(String message, int length)
        {
            String arg = @"^\d{"+length+"}$";
            Regex rex = new Regex(arg);
            if(message != "" && length > 0 && rex.IsMatch(message))
                return true;
            else
                return false;
        }

        /// <summary>
        /// 判断字符串是否为指定长度的小数字符串
        /// </summary>
        /// <param name="value"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static bool isDecimal(String value, int precision, int scale) {
            if (precision == 0) return false;
            string pattern = @"(^\d{1,"+precision+"}";
            if(scale>0)
                pattern += @"\.\d{0," + scale + "}$)|" + pattern ;
            pattern += "$)";

            return Regex.IsMatch(value,pattern);
        }

    }
}

.Net常用技巧_字符串检查与判断,布布扣,bubuko.com

时间: 2024-10-07 12:24:11

.Net常用技巧_字符串检查与判断的相关文章

.Net常用技巧_目录与文件操作

using System; using System.Collections.Generic; using System.Text; using System.IO; namespace MyTool { public class FileOperator { /// <summary> /// 返回指定目录下所有文件信息 /// </summary> /// <param name="strDirectory">目录字符串</param>

.Net常用技巧_操作Excel知识点

C#操作Excel知识点 近期在使用C#操作excel,主要是读取excel模板,复制其中的模板sheet页,生成多个sheet页填充相应数据后另存到excel文件,所用到的知识点如下. 一.添加引用和命名空间 添加Microsoft.Office.Interop.Excel引用,它的默认路径是C:\Program Files\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office12\Microsoft.Off

.Net常用技巧_汉字转拼音类(除汉字外,其余的原样输出)

注:如果是多音字,则默认取第一个拼音. using System; using System.Collections.Generic; using System.Text; using Microsoft.International.Converters.PinYinConverter; namespace MyTool { /// <summary> /// 汉字转拼音类 /// </summary> public class PinYinConver { public PinY

.Net常用技巧_软件注册码

using System; using System.Collections.Generic; using System.Text; using System.Management; using Utility; using EXDataControl; using System.Collections; using Microsoft.Win32; namespace MyTool { public class SoftReg { /// <summary> /// 获取硬盘卷标号 ///

.Net常用技巧_打印DataGridView(转)

选择相应的列进行打印报表.只需实例化带一个DataGridView参数的构造函数就可以使用 class PrintGridViewData { public PrintGridViewData() { } private DataGridView DGridView; public PrintGridViewData(DataGridView DGView) { DGridView = DGView; } private Form dialogForm = new Form(); private

.Net常用技巧_导出 Excel 和相关打印设置

Excel.Application myExcel = new Excel.Application();发 表Excel.Workbook workbookData = myExcel.Application.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);Excel.Worksheet xlSheet = (Worksheet)workbookData.Worksheets[1];//取得sheet1 1) 显示当前窗口: xlSheet.

.Net常用技巧_生成物料编号(根据分类代码生成)

这个是自己用的,不一定符合您的需求. using System; using System.Collections.Generic; using System.Text; using EXDataControl; using System.Data; using System.Data.SqlClient; using Utility; namespace MyTool { public class CreateMaterialCode { /// <summary> /// 获取新物料编号(

.Net常用技巧_读取XML某节点例子

注:此例子只是自己在代码中为了读某固定的几个值,写的有点死,所以另作他用的时候请自行修改或扩充 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Xml; namespace MyTool {

.Net常用技巧_传入DataGrid直接导出成Excel

注:非调用OFFICE的DLL方法. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; using Utility; using System.IO; names