L50H70 我想去掉 L 和 H 怎么搞呀得到 50 和 70 这2个数字

解决方案 »

  1.   

    L50万H70万 我想去掉 L 和 H 怎么搞呀 得到 50万 和 70万 这2个数字请写出具体方法  谢谢 
      

  2.   

    具体情况具体判断。LZ你的需求有可能只是这个string中的第一个字符。或者非数字,正则挺好用的,不过我都忘了。如果具体要去掉特定的字符如例子中的“L”“H”,可以索引后删除。
    如:
    int conIndex = con.IndexOf("L");
    con = con.Remove(conIndex);不过看楼主的例子,貌似只要去掉第一位。即:con = con.Remove(0);行么?
      

  3.   

    用正则的方法
    using System.Text.RegularExpressions;   void MatchRegex()
            {
                // 正则表达式匹配
                RegexOptions options = RegexOptions.None;
                Regex regex = new Regex(@"\d{2}", options);//匹配两位数字
                string input = @"L50H70";            // 检查匹配
                bool isMatch = regex.IsMatch(input);
                if (isMatch)
                {
                    Response.Write(input+"<br>");
                }            // 取出匹配值
                //Match match = regex.Match(input);
                //if (match != null)
                //{
                //    Response.Write(match.Value+"<br>");
                //}            // 得到多个子匹配
                MatchCollection matches = regex.Matches(input);
                for (int i = 0; i != matches.Count; ++i)
                {
                    Response.Write(matches[i].Value+"<br>");//输出匹配值
                }