jak-black

获取html 标记的值:

:

结果:您选择的是2014年1月22日

使用了Regex 对象,得到一个 MatchCollection,然后进行处理。

string mes = @"<input value=\'您选择的是\' type=\'checkbox\' size=5 name=年 >:<input value=2014 size=5 name=年 >年<input value=1 size=5 name=月 >月<input value=\'22\'  size=5 name=\'日\' >日";
            //获取所有的<input>标记
            Regex regAllInput = new Regex(@"(?is)<input [^>]*>");
            //获取 <input value=\'\'>的标记 
            //?value=([\'""]?)(?<showValue>[^\'""\s>]+)\1  给value 的值取个标记 showValue,MatchCollection 时候方便获取
            Regex regValue = new Regex(@"(?is)<input ?value=([\'""]?)(?<showValue>[^\'""\s>]+)\1 [^>]*>");
            MatchCollection mc = regAllInput.Matches(mes);//所有<input >标签集合
            string value_temp=string.Empty;
            foreach (Match m in mc)
            {
                //所有<input value=\'\' >标签集合
                MatchCollection mcItem = regValue.Matches(m.ToString());
                foreach (Match item in mcItem)
                {
                    value_temp=item.Groups["showValue"].Value;//获取value 值
                }               
                mes = mes.Replace(m.ToString(), value_temp);//进行替换
            }
            Console.WriteLine(mes);
            Console.ReadLine();

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-05
  • 2021-08-26
  • 2021-11-03
  • 2022-12-23
  • 2021-10-16
相关资源
相似解决方案