gpt4 book ai didi

c# - 无法将字符串转换为字符

转载 作者:行者123 更新时间:2023-11-30 13:51:45 25 4
gpt4 key购买 nike

昨晚我在这里得到了一些关于获取集合索引的帮助。这是我正在使用的代码。

            System.Text.StringBuilder sb = new System.Text.StringBuilder();

for (int i = 1; i < _prod.ActiveProductItemCollection.Count; i++)
{

sb.Append("<script type='text/javascript'>");
sb.Append("mboxCreate(\"product_productpage_rec{0}\")", i);
sb.Append("\"entity.id=" + _prodID + "\",");
sb.Append("\"entity.categoryId=" + _categoryID + "\",");
sb.Append("\"entity.name=" + _prod.ActiveProductItemCollection[i].Title + "\",");
sb.Append("\"entity.pageURL=" + Request.Url.ToString() + "\",");
//The following value has been taken from the productImageControl code behind.
//Might have to refactor in future as a property of the image control.
string filename = AppSettingsManager.Current.ProductImagePathLarge + _prod.ActiveProductItemCollection[i].Sku
+ AppSettingsManager.Current.ProductImageExtension;
sb.Append("\"entity.thumbnailURL=" + filename + "\",");
sb.Append("\"entity.inventory=" + _prod.ActiveProductItemCollection.Count + "\",");
sb.Append("\"entity.value=" + _prod.ActiveProductItemCollection[i].ActualPrice + "\",");
sb.Append("\"entity.ProductItemID=" + _prod.ActiveProductItemCollection[i].Sku + "\",");
sb.Append("\"entity.addToCartImg=~/Images/Buttons/btn_AddToCartFlat.gif\");<");
//The last line has to be /script. < inserted on prev line. do not change it or bad things will happen.
sb.Append("/script>");
}
this.LiteralMBoxScript.Text = sb.ToString();

我想做的是在 productpage_rec 之后获取集合中项目的索引。

例如,第一个产品会生成类似

mboxCreate("product_productpage_rec1"

依此类推集合中的每个产品。当我尝试构建时出现以下错误:

“无法从字符串转换为字符”

它在 product_productpage_rec 上出错了{0}

我错过了什么?

提前致谢。

最佳答案

  sb.AppendFormat("mboxCreate(\"product_productpage_rec{0}\")", i);

应该可以

关于c# - 无法将字符串转换为字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3997677/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com