1
Vote

Chinese compression

description

Hi,

I opened a question regarding the problem with compression of Chinese language:
http://stackoverflow.com/questions/13065510/asp-net-gzip-compression-for-chinese-language-with-jquery-ui-and-jqgrid/13068637#13068637


The problem was in:

///
    /// Convert string to byte[]
    /// Faster than the built-in method, and prevent encoding problems
    /// 
    /// 
    /// 
    public static byte[] StringToBytes(string value)
    {
        int length = value.Length;
        byte[] resultBytes = new byte[length];
        for (int i = 0; i < length; i++)
        {
            resultBytes[i] = (byte)value[i];
        }
        return resultBytes;
    }

Solved by changing that method to:

///
    /// Convert string to byte[]
    /// Faster than the built-in method, and prevent encoding problems
    /// 
    /// 
    /// 
    public static byte[] StringToBytes(string value)
    {
             Encoding Utf8 = Encoding.UTF8;
            return Utf8.GetBytes(value);
    }

comments