c#怎么才能将中文转换成utf-8编码

UTF8Encoding utf8 = new UTF8Encoding();String unicodeString = " 大西瓜 " ;Byte[] encodedBytes = utf8.GetBytes(unicodeString);String decodedString = utf8.GetString(encodedBytes);Response.Write(decodeString);


string s = BitConverter.ToString(System.Text.Encoding.UTF8.GetBytes("大西瓜"));

string s = "大西瓜";
            string code = "";
            foreach (byte b in Encoding.UTF8.GetBytes(s))
            {
                code += '%' + b.ToString("X");
            }
            Console.WriteLine(code);
public static string UrlEncode(string str)
{
    if (str == null)
    {
        return null;
    }
    return UrlEncode(str, Encoding.UTF8);
}

你可能感兴趣的:(String,C#,null,byte,encoding)