获取一串字符串结尾的数字(如果结尾为非数字,则返回0)

        public decimal GetStringLastNumber(string str)
        {
            decimal result = 0;
            if (str != null && str != string.Empty)
            {
                Match match = Regex.Match(str, @"(^.+?)(\d+$)");
                if(match.Success)
                {
                    result = decimal.Parse(match.Groups[2].Value);
                }
            }
            return result;
        }
posted @ 2012-11-15 15:47  therockthe  阅读(969)  评论(0编辑  收藏  举报