zoukankan      html  css  js  c++  java
  • c# 获取字符串中的数字

    c# 获取字符串中的数字
    ///
    /// 获取字符串中的数字
    ///
    /// 字符串
    /// 数字
    public static decimal GetNumber(string str)
    {
        decimal result = 0;
        if (str != null && str != string.Empty)
       {
    // 正则表达式剔除非数字字符(不包含小数点.)
        str = Regex.Replace(str, @"[^\d.\d]", "");
    // 如果是数字,则转换为decimal类型
        if (Regex.IsMatch(str, @"^[+-]?\d*[.]?\d*$"))
        {
        result = decimal.Parse(str);
        }
     }
       return result;
    }
    ///
    /// 获取字符串中的数字
    ///
    /// 字符串
    /// 数字
    public static int GetNumberInt(string str)
    {
    int result = 0;
    if (str != null && str != string.Empty)
    {
    // 正则表达式剔除非数字字符(不包含小数点.)
    str = Regex.Replace(str, @"[^\d.\d]", "");
    // 如果是数字,则转换为decimal类型
    if (Regex.IsMatch(str, @"^[+-]?\d*[.]?\d*$"))
    {
    result = int.Parse(str);
    }
    }
    return result;
    }


    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/jiaao/archive/2008/07/09/2628982.aspx

  • 相关阅读:
    GitHub 实现多人协同提交代码并且权限分组管理
    前端第一篇文章-http标准
    介绍Android电量
    音频编码格式
    PPT
    Word
    HTML 之 JavaScript
    HTML 之 CSS
    HTML 之 HTTP 协议(请求协议以及响应协议)
    HTML 之 标签
  • 原文地址:https://www.cnblogs.com/chenlong/p/1601960.html
Copyright © 2011-2022 走看看