请问大佬:在C#中,在文本文件中可以快速查找想要的值呢?

hzy999 2004-10-26 03:39:30
例如:
<html>
<body>
<input id="button1" type="button">
<intpu id="button2" type="input">
<input id ="button3" type="button">
<input id="button4" type ="submid">
<input id="button5" type="button">
</body>
</html>
在这样的文本中查找type为button的所有的id.文体中可能很大
...全文
292 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
nga96 2005-02-13
  • 打赏
  • 举报
回复
实在不行就自己写代码吧,
ggdayup 2005-02-12
  • 打赏
  • 举报
回复
自己看了看regular expression,
(?<id>[^\"]+)
表示:
将非"的值加入名为id的组中。

整个"id=\"(?<id>[^\"]+)\" type=\"button\""表示:
"
id=
\"
(?<id>[^\"]+)
\"

type=
\"
button
\"
"



ggdayup 2005-02-08
  • 打赏
  • 举报
回复
有没有人帮忙解释一下这一段呢?
"(?<id>[^\"]+)\
谢谢!
mobydick 2005-01-25
  • 打赏
  • 举报
回复
正则表达式需要根据需要改变。
mobydick 2005-01-25
  • 打赏
  • 举报
回复
正则表达式
string regexStr = "id=\"(?<id>[^\"]+)\" type=\"button\"";
Regex regex = new Regex(regexStr, RegexOptions.IgnoreCase); //忽略大小写
string yourStr = @"<html>
<body>
<input id="button1" type="button">
<intpu id="button2" type="input">
<input id ="button3" type="button">
<input id="button4" type ="submid">
<input id="button5" type="button">
</body>
</html>";

MatchCollection mc = regex.Matches(yourStr);
foreach(Match m in mc)
{
string temp = m.Group["id"].Value;
}
xzyan80 2005-01-25
  • 打赏
  • 举报
回复
bu zhi dao
hzy999 2004-10-27
  • 打赏
  • 举报
回复
没有高手吗?
tangi 2004-10-27
  • 打赏
  • 举报
回复
文本读入String,然后查找。。。这还不容易嘛
hzy999 2004-10-26
  • 打赏
  • 举报
回复
也就是说,要找type为button的所有ID.文本如下:
<html>
<body>
<input id="button1" type="button">
<intpu id="button2" type="input">
<input id ="button3" type="button">
<input id="button4" type ="submid">
<input id="button5" type="button">
</body>
</html>
shuker 2004-10-26
  • 打赏
  • 举报
回复
不懂

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧