string price1="5.35元/公斤";
string price2="0.8807元/米";
string price3="1000元/10斤";
如何获得值
vprice1=5.35
vprice2=0.8807
vprice2=1000

解决方案 »

  1.   

    string price1="5.35元/公斤";
     string price2="0.8807元/米";
     string price3="1000元/10斤";  Regex reg = new Regex(@"([0-9,\.]*)?[\s\S]*$");
     
     Response.Write(reg.Matches(price1)[0].Result("$1")+"<BR>");
      Response.Write(reg.Matches(price2)[0].Result("$1")+"<BR>");
      Response.Write(reg.Matches(price3)[0].Result("$1")+"<BR>");
      

  2.   

    string yourStr = ......;
    MatchCollection mc = Regex.Matches(yourStr, "\\b(\\S+)=\"(\\d+(\\.\\d+)?)");
    foreach(Match m in mc)
    {
        m.Groups[1].Value;//price1、2、3
        m.Groups[2].Value;//
    }