******字符串替换问题

OceanRain 2009-06-10 03:41:44
<!-- AspNetPager V7.0.2 for VS2005 & VS2008 Copyright:2003-2007 Webdiyer (www.webdiyer.com) -->
<div id="Pager" style="text-align:right;">
<a disabled="disabled" style="margin-right:5px;">首页</a><a disabled="disabled" style="margin-right:5px;">上一页</a><span style="margin-right:5px;font-weight:Bold;color:red;">1</span><a href="javascript:__doPostBack('Pager','2')" style="margin- right:5px;">2</a><a href="javascript:__doPostBack('Pager','3')" style="margin-right:5px;">3</a><a href="javascript:__doPostBack ('Pager','4')" style="margin-right:5px;">4</a><a href="javascript:__doPostBack('Pager','2')" style="margin- right:5px;">下一页</a><a href="javascript:__doPostBack('Pager','4')" style="margin-right:5px;">末页</a>
</div>
<!-- AspNetPager V7.0.2 for VS2005 & VS2008 End -->

要求:移除外层的div,将javascript:__doPostBack('Pager','2')替换成诸如:http://www.sohu.com/2
结果:
<div id="Pager" style="text-align:right;">
<a disabled="disabled" style="margin-right:5px;">首页</a><a disabled="disabled" style="margin-right:5px;">上一页</a><span style="margin-right:5px;font-weight:Bold;color:red;">1</span><a href="http://www.sohu.com/2" style="margin- right:5px;">2</a><a href="http://www.sohu.com/3" style="margin-right:5px;">3</a><a href="http://www.sohu.com/4" style="margin-right:5px;">4</a><a href="http://www.sohu.com/2" style="margin- right:5px;">下一页</a><a href="http://www.sohu.com/4" style="margin-right:5px;">末页</a>
</div>
...全文
118 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
纠结的程序猿 2009-06-11
  • 打赏
  • 举报
回复
下载PilotEdit 2.5, http://topic.csdn.net/u/20090512/21/99628cbd-3c70-4d29-91ff-1962f01e7a7c.html

用下面的正则表达式查找替换:
查找:javascript:__doPostBack[ ]*\('Pager','?'\)
替换为:http://www.sohu.com/%04


假设原始文件为:
<div id="Pager" style="text-align:right;">
<a disabled="disabled" style="margin-right:5px;">首页 </a> <a disabled="disabled" style="margin-right:5px;">上一页 </a> <span style="margin-right:5px;font-weight:Bold;color:red;">1 </span> <a href="javascript:__doPostBack('Pager','2')" style="margin- right:5px;">2 </a> <a href="javascript:__doPostBack('Pager','3')" style="margin-right:5px;">3 </a> <a href="javascript:__doPostBack ('Pager','4')" style="margin-right:5px;">4 </a> <a href="javascript:__doPostBack('Pager','2')" style="margin- right:5px;">下一页 </a> <a href="javascript:__doPostBack('Pager','4')" style="margin-right:5px;">末页 </a>
</div>


将被转换为:
<div id="Pager" style="text-align:right;">
<a disabled="disabled" style="margin-right:5px;">首页 </a> <a disabled="disabled" style="margin-right:5px;">上一页 </a> <span style="margin-right:5px;font-weight:Bold;color:red;">1 </span> <a href="http://www.sohu.com/2" style="margin- right:5px;">2 </a> <a href="http://www.sohu.com/3" style="margin-right:5px;">3 </a> <a href="http://www.sohu.com/4" style="margin-right:5px;">4 </a> <a href="http://www.sohu.com/2" style="margin- right:5px;">下一页 </a> <a href="http://www.sohu.com/4" style="margin-right:5px;">末页 </a>
</div>
OceanRain 2009-06-10
  • 打赏
  • 举报
回复
这样的问题,大家平时怎么解决的?
OceanRain 2009-06-10
  • 打赏
  • 举报
回复
OceanRain 2009-06-10
  • 打赏
  • 举报
回复
谢谢
keystudio 2009-06-10
  • 打赏
  • 举报
回复

str = Regex.Replace(str, "(?<=<a\s*href=\")javascript:__doPostBack\('Pager','(?<p>\d*)'\)(?=\")", "http://www.sohu.com/${p}", RegexOptions.IgnoreCase);
rainsome 2009-06-10
  • 打赏
  • 举报
回复
OceanRain 2009-06-10
  • 打赏
  • 举报
回复
用正则实现,本人觉得最方便。欢迎大家讨论
OceanRain 2009-06-10
  • 打赏
  • 举报
回复
用正则实现
OceanRain 2009-06-10
  • 打赏
  • 举报
回复
不要看这么多的内容,其它就一个正则表达式
yangjiang113 2009-06-10
  • 打赏
  • 举报
回复

62,266

社区成员

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

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

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

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