【问题标题】:French Characters in SQL Text field to UTF - 8SQL 文本字段中的法语字符到 UTF - 8
【发布时间】:2015-07-28 22:16:49
【问题描述】:

我在 Sql Server 的文本列中存储了一些法语字符(不是 ntext,而是文本)。当我在 html 上显示它时,我会在字符串中得到一些有趣的问号字符。

即使我将文本转换为 nvarchar(max) 并在 html 上显示,我仍然会遇到同样的错误。

如何将文本字段中的法语字符正确转换为 UTF-8?我正在使用 C#、.NET 4.5。

谢谢你, 考试成绩

【问题讨论】:

  • 可能是也可能不是数据库问题。
  • 请参阅:stackoverflow.com/a/11432833/1291428。大多数情况下,这个答案是针对 mysql 的,但有些部分适用于任何系统。
  • 可能是 HTML 编码不匹配。试试<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  • text 不会正确存储法语字符。你需要ntext。现在,如果您从text 开始,然后“转换”为nvarchar,您已经丢失了Unicode 字符。您需要使用 unicode 字段类型 ntextnvarchar 并重新导入数据。

标签: c# sql-server encoding utf-8


【解决方案1】:

这样修复它:

Encoding wind1252 = Encoding.GetEncoding(1252);
Encoding utf8 = Encoding.UTF8;
byte[] wind125Bytes = wind1252.GetBytes(input);
byte[] data = Encoding.Convert(wind1252, utf8, wind125Bytes);

【讨论】:

    猜你喜欢
    • 2011-02-22
    • 1970-01-01
    • 1970-01-01
    • 2011-08-06
    • 2015-10-12
    • 2013-04-13
    • 2011-05-24
    • 1970-01-01
    • 2015-06-04
    相关资源
    最近更新 更多