【问题标题】:remove html input tag from string using C#使用 C# 从字符串中删除 html 输入标记
【发布时间】:2014-04-15 08:54:34
【问题描述】:
<pre>
    <p>The accounting equation asset = capital + liabilities, which of the following is true. Ram has started business with 5,50,000 and has purchased goods worth 1,50,000 on credit</p><p>
    <input type='radio' id='op1' name='q2option' value='1' /> a) 7,00,000 = 5,50,000 + 1,50,000 
    <input type='radio' id='op2' name='q2option' value='2' />b)7,00,000 = 6,50,000 + 50,000</p>
    <p> 
    <input type='radio' id='op3' name='q2option' value='3' /> c) 5,50,000 = 7,00,000 - 1,50,000 
    <input type='radio' id='op3' name='q2option' value='4' > d)5,50,000 = 5,00,000 + 50,000</p>
</pre>

我想在 Windows 应用程序的 C#.Net 中删除输入标记 我已更改输入标签结构以显示代码

【问题讨论】:

  • 太棒了。前进。如果您遇到问题,请告诉我们。
  • 不知道你在这里要求什么......
  • 如果您的字符串总是这样(假设输入标签格式正确并且您的示例有错字),您可以解析它并删除 &lt;&gt; 之间的所有字符串。你应该寻找String.Substring()String.IndexOf() 方法,它们会帮助你
  • 我想使用 c#.Net 从 html 中删除单选按钮...
  • 是否有任何正则表达式可以删除单选按钮

标签: c# html regex


【解决方案1】:

您可以使用正则表达式从字符串中删除输入标签:

var temp = "The accounting equation asset = capital + liabilities, which of the             following is true. Ram has started business with 5,50,000 and has purchased goods worth 1,50,000 on credit <input type='radio' id='op1' name='q2option' value='1' /> a) 7,00,000 = 5,50,000 + 1,50,000 <input type='radio' id='op2' name='q2option' value='2' />b)7,00,000 = 6,50,000 + 50,000 <input type='radio' id='op3' name='q2option' value='3' /> c) 5,50,000 = 7,00,000 - 1,50,000 <input type='radio' id='op3' name='q2option' value='4' /> d)5,50,000 = 5,00,000 + 50,000";

var regInput = new Regex("(.*?)(\\<input[^\\>]*\\>)(.*?)");

var result =regInput.Replace(temp,"$1$3");

【讨论】:

  • 也许再试一次,我更改了表达式,因为如果输入标签之间没有换行符,它就不起作用
猜你喜欢
  • 2010-09-19
  • 2017-09-06
  • 1970-01-01
  • 2013-02-21
相关资源
最近更新 更多