一个关于字符串转换的问题

jimmy893 2009-04-10 09:11:22
我有这样一个带有html标记的字符串
string str= "<p><font size="3">    Go back nearly 30 000 years and you will find out <u>{1}</u> carving painting and molding their visions of the world and <u>{2}</u> into the rocky surfaces of Africa. As a <u>{3}</u> David Colsens has spent years documenting the Art.<br />
    We <u>{4}</u> that the number of sites in Africa is well over a million you know It's probably closer to five million. And if you think that each site could have <u>{5}</u> of images you get some idea of the enormous extent of this art you know it is quite <u>{6}</u>. Equally extraordinary experts say is how closly their thoughts and struggles mirror those <u>{7}</u> today. <br />
    They were trying to express their congnitive system. They were trying to look at the <u>{8}</u> reality. They were looking at issues that were depiction of <u>{9}</u> kinds of thoughts and all this together really reprensents the way they looked at their whole <u>{10}</u>.</font></p>"

其中有10个 <u>{*}</u> 这样的字符串
如何把这10个字符串取出来放进一个数组中,
然后分别转换成文本框"<input type='text' id='txt*' name='txt*' />",id设置为txt+大括号中的数字
转换完毕之后,再分别放回到字符串中将之前的<u>{*}</u>替换掉

如果还有其他好的办法来解决,那更好
现在主要问题就是,转换成文本框时,要设置不同的ID和name

50分求解,请各位不吝赐教
...全文
88 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
wang355 2009-04-10
  • 打赏
  • 举报
回复
你要用FreeTextBox控制的话,很简单
syc958 2009-04-10
  • 打赏
  • 举报
回复
可以用正则来匹配
ccimage 2009-04-10
  • 打赏
  • 举报
回复
html代码可以使用一个webbrowser控件来处理,相当简单
wangrumeng 2009-04-10
  • 打赏
  • 举报
回复
不会
BossFriday 2009-04-10
  • 打赏
  • 举报
回复
其中有10个 <u>{*} </u> 这样的字符串
用正则:
Match mymatch=Regex.Match(inputStr,RegexStr,RegexOptions.IgnoreCase);
while ( mymatch.Success )
{
yourArrayList.Add(mymatch.Value )
mymatch = mymatch.NextMatch();
}

转换完毕之后,再分别放回到字符串中将之前的 <u>{*} </u>替换掉
这个还是正则替换
Regex.Replace(inputStr,RegexStr)

这个两个方法配合使用,一般抓站的程序就完成了.
估计你是要搞一个抓站程序吧?其实工作量就是硬分析这些htmlString
Jerry_hu 2009-04-10
  • 打赏
  • 举报
回复
xsm545 2009-04-10
  • 打赏
  • 举报
回复
学习..帮顶
jimmy893 2009-04-10
  • 打赏
  • 举报
回复
正解在此
str = Regex.Replace(str, @"<u>{(?<n>\d*)}</u>", "<input type='text' id='txt${n}' name='txt${n}' />", RegexOptions.IgnoreCase);

walkghost 2009-04-10
  • 打赏
  • 举报
回复
正则。
chouto 2009-04-10
  • 打赏
  • 举报
回复
正则取出来,生成<input type='text' id='txt*' name='txt*' />,再替换

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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