zoukankan      html  css  js  c++  java
  • 字符集的问题

    AX中的字符型字段用的是NVchar类型,编码是Unicode,这是通用的编码方式,支持多国语言字符的数据。但是如果要将AX里的数据导出到不支持Unicode的系统中就有些麻烦了,用SSIS的简体中文字符集导出时如果遇到简体中文字符集不支持的字符它就会报错了。用如下代码可以找到简体中文不支持的字符。

    代码
    SqlCommand sqlCommand = new SqlCommand("select nameAlias from InventTable", sqlConnection);
                SqlDataReader dataReader 
    = sqlCommand.ExecuteReader();
                
    while (dataReader.Read())
                {
                    
    string nameAlias = dataReader.GetValue(0).ToString();
                    
    byte[] gb2312 = System.Text.Encoding.Convert(System.Text.Encoding.Unicode, System.Text.Encoding.GetEncoding("GB2312"), System.Text.Encoding.Unicode.GetBytes(nameAlias));
                    
    char[] gb2312Char = new char[System.Text.Encoding.GetEncoding("GB2312").GetCharCount(gb2312, 0, gb2312.Length)];
                    System.Text.Encoding.GetEncoding(
    "GB2312").GetChars(gb2312, 0, gb2312.Length, gb2312Char,0);
                    
    string gb2312String = new string(gb2312Char);
                    
                    
    if (nameAlias != gb2312String)
                    {
                        Console.WriteLine(nameAlias);
                        Console.WriteLine(gb2312String);
                    }
                }
  • 相关阅读:
    格式化输出函数(1): Format
    ini 文件操作记要(2): 使用 TMemIniFile
    文本文件读写
    格式化输出函数(3): FormatFloat
    Delphi 中的哈希表(2): TStringHash
    格式化输出函数(2): FormatDateTime
    Delphi 中的哈希表(1): THashedStringList
    调用系统关于对话框
    在Ubuntu上安装Thrift并调通一个例子
    rpm2html/rpmfind
  • 原文地址:https://www.cnblogs.com/Farseer1215/p/1876884.html
Copyright © 2011-2022 走看看