C# 使用正则表达式去掉字符串中的数字

C# 使用正则表达式去掉字符串中的数字

/// <summary>
/// 去掉字符串中的数字
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static string RemoveNumber(string key)
{
    return System.Text.RegularExpressions.Regex.Replace(key, @"\d", "");
}

 

 

 

/// <summary>
/// 去掉字符串中的非数字
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static string RemoveNotNumber(string key)
{
    return System.Text.RegularExpressions.Regex.Replace(key, @"[^\d]*", "");
}

 

 

 

 效果:输入"High:4"

 

第一个函数,输出结果是"High:"

 

第二个函数,输出结果是"4"

 

posted @ 2011-01-13 16:11  DODUI  阅读(1154)  评论(0编辑  收藏  举报