提取字符串中字母数字方法

//提取数字
public static IList<int> GetNumberic(string str)
{
    IList<int> numbericList=new List<int>();
    MatchCollection ms = Regex.Matches(str, @"\d+");
    foreach(Match m in ms)
    {
       numbericList.Add(m.Value);
    }
    return numbericList;
}
//提取字母
public static IList<string> GetStrings(string str)
{
    IList<string> strList=new List<string>();
    MatchCollection ms = Regex.Matches(str, @"\D+");
    foreach(Match m in ms)
    {
       strList.Add(m.Value);
    }
    return strList;
}

 

posted @ 2016-11-11 11:34  我的名称很霸气  阅读(1958)  评论(0编辑  收藏  举报