c# - 用于使用 StringBuilder 显示多个 HTML 页面而不是仅显示一个 (ASP.NET) 的语句
问题描述
我的 for 语句正在打印 10 个 HTML 页面,而我只需要一个带有 10 个替换和添加 div 标签的编辑过的 HTML 页面。我正在使用 Regex.Replace 查找链接并在之前添加一个 z-index div 标签,以便我可以用数字突出显示每个链接。
protected void Page_Load(object sender, EventArgs e)
{
string con = ("Data Source=Desktop-7k2gnco;Initial Catalog=trackingstats;"
+ "Integrated Security=SSPI");
string queryString =
"select CampaignId, ConvertedCreative from CampaignAdCopy where CampaignId = 24896;";
using (SqlConnection connection =
new SqlConnection(con))
{
SqlCommand command = new SqlCommand(queryString, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
string CampaignId = reader["CampaignId"].ToString();
string htmlCreate= reader["ConvertedCreative"].ToString();
StringBuilder strContents = new StringBuilder();
for (int i = 1; i < 11; i++)
{
string replacement = "<div style=\"z-indexer:1;background:#0c538e;width:2.25em;height:2.25em;text-align:center;color:white;\">" + i + "</div><a href=\"http://www.trackingstats.info/Process.aspx.c=/" + CampaignId + "&l=" + i + "\"";
Regex regex = new Regex("<a href=\"http://www.trackingstats.info/Process.aspx.c=24896&l="+ i +"\"", RegexOptions.IgnoreCase);
string result = regex.Replace(htmlCreate, replacement);
strContents.AppendLine(result);
}
Label1.Text = strContents.ToString();
}
}
}
解决方案
推荐阅读
- node.js - 在 ejs 模板文件中使用 mongoose 获取数据
- json - Marshal Unmarshal JSON 结构问题导致 REST 请求失败
- python - 如何在opencv中获取匹配模板的位置?
- c - 致命错误:asm/atomic.h:debian10 os 上没有这样的文件或目录
- node.js - 续集 Postgres 我可以通过 updatedAt 订购吗
- mongodb - 如何使用聚合连接 mongodb 中的多级集合?
- c++ - C++ 模板,链接阶段未定义的引用错误
- r - data.table 与 tidyr::expand_grid
- rest - 设计 RESTful API 时如何解决模棱两可的 404
- boolean - bool 类型值的偏移量