foreach (string 水果名 in 查表得来的数组)
{
content.Replace(水果名, "<a href=\"class" + 对应的classID + ".html\">" + 水果名 + "</a>");
}
{
content.Replace(水果名, "<a href=\"class" + 对应的classID + ".html\">" + 水果名 + "</a>");
}
调试欢乐多
{
strSql = "SELECT * from [class] order by aID desc";
SqlConnection objConnection = new SqlConnection(ConfigurationSettings.AppSettings["dns"]);
objConnection.Open();
SqlCommand cmd = new SqlCommand(strSql, objConnection);
SqlDataReader dr = cmd.ExecuteReader();
int i = 1;
while (dr.Read())
{
if (i == 1)
{
aname += "" + dr["aname"] + "";
}
else
{
aname += "," + dr["aname"] + "";
}
i++;
}
dr.Close();
objConnection.Close();
}
protected void BtnSubmit_Click(object sender, EventArgs e)
{
string content= Request.Params["content"]; string[] conArr = Regex.Split(aname, ",");
int pageCount = conArr.Length; for (int p = 0; p < pageCount; p++)
{
aname = conArr[p]; lastcontent += content.ToString().Replace(aname, "<a href=class" + aid+ ".html>" + aname+ "</a>");
}
Response.Write(lastcontent);
}
我现在是用这个写的,但出来的结果是,提示出错,没有aid ,请问这里的AID怎么获取?还有一个主要的,没有这里的AID的话,我发现它匹配了所有的后,有几个匹配的,所有的内容就重复出现几次,主要是lastcontent +=我这里用了 += ,但如果只用一个 = 的话,出现的是,不能匹配,请问帮忙处理下,谢谢
content最好用StringBuilderfor (int p = 0; p < pageCount; p++)
{
aname = conArr[p]; content = content.ToString().Replace(aname, " <a href=class" + aid+ ".html>" + aname+ " </a>");
} lastcontent = content;
{
if (i == 1)
{
aname += "" + dr["aname"] + "";
}
else
{
aname += "," + dr["aname"] + "";
}
i++;
}
这里一样啊,可以用结构存取,自己定义一个结构
例如
struct FruitInfo
{
public string name;
public int aid;
};
不过不知道网页可不可以这么干,没做过网站
不行的话
用类似于"1 苹果,2 香蕉, 3 毛桃"的方法做2次字符串处理
如下
for (int p = 0; p < pageCount; p++)
{
string []perFruitInfo= Regex.Split(conArr[p], " "); content = content.ToString().Replace(aname, " <a href=class" + perFruitInfo[0]+ ".html>" + perFruitInfo[1]+ " </a>");
}
异常处理自己加