我想改变在网页上看起来不错的分数,但是当通过存储的proc添加到数据库时,它们产生一个?
这是我试图去工作的代码.... Contains()方法与分数和触发器一起使用,但Replace()不会替代:(任何帮助,非常感谢!
foreach (ListItem Item in lboxIng.Items) { fracCheck = Item.ToString(); if (fracCheck.Contains("⅓")) { fracCheck.Replace("⅓", "1/3"); listString += fracCheck; } else if (fracCheck.Contains("⅔")) { fracCheck.Replace("⅔", "2/3"); listString += fracCheck; } else { listString += Item; } ingList.Add(listString); }I want to change the fractions that look nice on a webpage, but when added to database through stored proc they produce a ?
This is the code I'm trying to get to work....the Contains() method works with the fractions and triggers but the Replace() doesn't replace :( Any help is greatly appreciated!
foreach (ListItem Item in lboxIng.Items) { fracCheck = Item.ToString(); if (fracCheck.Contains("⅓")) { fracCheck.Replace("⅓", "1/3"); listString += fracCheck; } else if (fracCheck.Contains("⅔")) { fracCheck.Replace("⅔", "2/3"); listString += fracCheck; } else { listString += Item; } ingList.Add(listString); }最满意答案
Replace方法不会修改字符串,但会返回字符串的修改版本。 所以你需要将Replace的返回值赋给变量:
fracCheck = fracCheck.Replace("⅓", "1/3");代码的简短版本:
foreach (ListItem Item in lboxIng.Items) { var fracCheck = Item.ToString(); fracCheck = fracCheck.Replace("⅓", "1/3"); fracCheck = fracCheck.Replace("⅔", "2/3"); ingList.Add(fracCheck); }更好的方法是将数据库更改为使用unicode字符集,以便可以在其中存储任何文本。
The Replace method does not modify the string, but returns a modified version of the string. So you need to assign the return value of Replace to the variable:
fracCheck = fracCheck.Replace("⅓", "1/3");Short version of your code:
foreach (ListItem Item in lboxIng.Items) { var fracCheck = Item.ToString(); fracCheck = fracCheck.Replace("⅓", "1/3"); fracCheck = fracCheck.Replace("⅔", "2/3"); ingList.Add(fracCheck); }A much better approach is to change your database to use a unicode characterset, so that you can store any text in it.
更多推荐
发布评论