如何用字符串中的1/3替换to以存储在数据库中(How to replace ⅓ with 1/3 in a string to store in a database)

编程入门 行业动态 更新时间:2024-10-25 06:20:16
如何用字符串中的1/3替换to以存储在数据库中(How to replace ⅓ with 1/3 in a string to store in a database)

我想改变在网页上看起来不错的分数,但是当通过存储的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.

更多推荐

本文发布于:2023-07-27 15:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1292402.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   数据库中   如何用   replace   store

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!