【问题标题】:SQL db from ASCII to UnicodeSQL db 从 ASCII 到 Unicode
【发布时间】:2012-12-19 13:55:41
【问题描述】:

My SQL Server 2008 R2 数据库具有字符串列 (nvarchar)。一些旧数据显示 ASCII。我需要在我的站点中向用户展示它,并且我更喜欢将数据库中的数据转换为 Unicode。有没有快速的方法来做到这一点?我应该注意哪些缺点?

我的问题示例:

在数据库中,我看到特殊字符而不是常规字符。我有一个用户名,应该是Amédée,但它显示的是Am?d??

在其他情况下,我看到 " 而不是引号 ("),或者字符 &# 而不是单词 "and"

【问题讨论】:

  • 您如何查看数据库中的数据?选择语句? SSMS?你的网站?

标签: unicode sql-server-2008-r2 ascii type-conversion


【解决方案1】:

如果您的数据库中有重音字符,那肯定不是 ASCII。首先找出您/他们在旧数据库中使用的代码页,并将其转换为 UTF-8,然后保存到新数据库。

【讨论】:

    【解决方案2】:

    我构建了以下函数:

     public static string FixString(string textString)
            {
                textString = Regex.Replace(textString, "[\t\r\n]*", String.Empty);
                textString = Regex.Replace(textString, "(\\ )+", " ").Replace("  ", " ").Trim(); // .Replace("-", " ");
                textString = Regex.Replace(textString, "\\(.*?\\)", String.Empty);
                textString = HttpUtility.HtmlDecode(textString).Trim();
                textString = Regex.Replace(textString, "<.*?>", String.Empty);
                return textString;
            }
    

    那成功了!!!

    【讨论】:

      猜你喜欢
      • 2018-08-25
      • 2011-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-05
      • 1970-01-01
      • 2010-09-12
      • 2011-04-06
      相关资源
      最近更新 更多