C# 通用方法

一、
/// <summary> /// 删除字符串中的中文 /// </summary> public static string Delete(string str) { string retValue = str; if (System.Text.RegularExpressions.Regex.IsMatch(str, @"[\u4e00-\u9fa5]")) { retValue = string.Empty; var strsStrings = str.ToCharArray(); for (int index = 0; index < strsStrings.Length; index++) { if (strsStrings[index] >= 0x4e00 && strsStrings[index] <= 0x9fa5) { continue; } retValue += strsStrings[index]; } } return retValue; }

 

二、  
/// <summary>
        /// 判断字符串是否是数字,只针对Int类型,double不行
        /// </summary>
        public static bool IsNumber(string s)
        {
            if (string.IsNullOrWhiteSpace(s)) return false;
            const string pattern = "^[0-9]*$";
            Regex rx = new Regex(pattern);
            return rx.IsMatch(s);
        }

/// <summary>
/// 判断字符串是否是 int或double,为int或double时返回true
///可用于界面上经纬度值判定
/// </summary> public static bool IsIntOrDouble(string strNumber) { Regex objNotNumberPattern = new Regex("[^0-9.-]"); Regex objTwoDotPattern = new Regex("[0-9]*[.][0-9]*[.][0-9]*"); Regex objTwoMinusPattern = new Regex("[0-9]*[-][0-9]*[-][0-9]*"); const string strValidRealPattern = "^([-]|[.]|[-.]|[0-9])[0-9]*[.]*[0-9]+$"; const string strValidIntegerPattern = "^([-]|[0-9])[0-9]*$"; Regex objNumberPattern = new Regex("(" + strValidRealPattern + ")|(" + strValidIntegerPattern + ")"); return !objNotNumberPattern.IsMatch(strNumber) && !objTwoDotPattern.IsMatch(strNumber) && !objTwoMinusPattern.IsMatch(strNumber) && objNumberPattern.IsMatch(strNumber); }

C#怎么判断字符是不是汉字

 

三、数字前补0

int number = 001;
var aa = "";
if (number > 1000)
{
aa = number.ToString();
}
else
{
aa = number.ToString().PadLeft(4, '0'); // 一共4位,位数不够时从左边开始用0补
}

 

四、Stream 和 byte[] 的相关转换

 

转载于:https://www.cnblogs.com/macT/p/9401290.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
----------Database-------------- 1.DataTable帮助类(DataTableHelper.cs) 2.Access数据库文件操作辅助类(JetAccessUtil.cs) 5.查询条件组合辅助类(SearchCondition.cs) 6.查询信息实体类(SearchInfo.cs) 8.Sql命令操作函数(可用于安装程序的时候数据库脚本执行)(SqlScriptHelper.cs) ----------Device-------------- 声音播放辅助类(AudioHelper.cs) 摄像头操作辅助类,包括开启、关闭、抓图、设置等功能(Camera.cs) 提供用于操作【剪切板】的方法(ClipboardHelper.cs) 获取电脑信息(Computer.cs) 提供用户硬件唯一信息的辅助类(FingerprintHelper.cs) 读取指定盘符的硬盘序列号(HardwareInfoHelper.cs) 提供访问键盘当前状态的属性(KeyboardHelper.cs) 全局键盘钩子。这可以用来在全球范围内捕捉键盘输入。(KeyboardHook.cs) 模拟鼠标点 击(MouseHelper.cs) 全局鼠标钩子。这可以用来在全球范围内捕获鼠标输入。(MouseHook.cs) MP3文件播放操作辅助类(MP3Helper.cs) 关联文件(ExtensionAttachUtil.cs) 注册文件关联的辅助类(FileAssociationsHelper.cs) 打开、保存文件对话框操作辅助类(FileDialogHelper.cs) 常用的文件操作辅助类FileUtil(FileUtil.cs) INI文件操作辅助类(INIFileUtil.cs) 独立存储操作辅助类(IsolatedStorageHelper.cs) 序列号操作辅助类(Serializer.cs) 获取一个对象,它提供用于访问经常引用的目录的属性。(SpecialDirectories.cs) 简单的Word操作对象(WordCombineUtil.cs) 这个类提供了一些实用的方法来转换XML和对象。(XmlConvertor.cs) XML操作类(XmlHelper.cs) ----------Format-------------- 参数验证的通用验证程序。(ArgumentValidation.cs) 这个类提供了实用方法的字节数组和图像之间的转换。(ByteImageConvertor.cs) byte字节数组操作辅助类(BytesTools.cs) 处理数据类型转换,数制转换、编码转换相关的类(ConvertHelper.cs) CRC校验辅助类(CRCUtils.cs) 枚举操作公共类(EnumHelper.cs) 身份证操作辅助类(IDCardHelper.cs) 检测字符编码的类(IdentifyEncoding.cs) RGB颜色操作辅助类(MyColors.cs) 日期操作类(MyDateTime.cs) 转换人民币大小金额辅助类(RMBUtil.cs) 常用的字符串常量(StringConstants.cs) 简要说明TextHelper。(StringUtil.cs) 获取中文字首字拼写,随机发生器,按指定概率随机执行操作(Util.cs) 各种输入格式验证辅助类(ValidateUtil.cs) ----------Network-------------- Cookie操作辅助类(CookieManger.cs) FTP操作辅助类(FTPHelper.cs) HTML操作类(HttpHelper.cs) 网页抓取帮助(HttpWebRequestHelper.cs) Net(NetworkUtil.cs) IE代理设置辅助类(ProxyHelper.cs) ----------Winform-------------- 跨线程的控件安全访问方式(CallCtrlWithThreadSafety.cs) CheckBoxList(CheckBoxListUtil.cs) 窗口管理类(ChildWinManagement.cs) 由马丁·米勒http://msdn.microsoft.com/en-us/library/ms996492.aspx提供一个简单的方法打印工作的一个RichTextBox一个帮手(ExRichTextBoxPrintHelper.cs) 显示,隐藏或关闭动画形式。(FormAnimator.cs) 对窗体进行冻结、解冻操作辅助类(FreezeWindowUtil.cs) 窗体全屏操作辅助类(Ful

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值