本文介绍了我想在ASP.NET MVC中获得UTF-16BE字符串代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 此功能无法正常工作。应该返回092F09420928093F0915094B0921但是再次返回。 我尝试过: this function not working properly.it should be return "092F09420928093F0915094B0921" but return यूनिकोड again.What I have tried:public ActionResult encode() { string myString = "यूनिकोड "; string result = ""; byte[] bytes = System.Text.Encoding.UTF8.GetBytes(myString); result = System.Text.Encoding.UTF8.GetString(bytes); return Content(result); } 推荐答案 如果你想要UTF-16BE,你必须使用 Encoding.BigEndianUnicode Property(System.Text) [ ^ ]。转换使用 Encoding.Convert方法(编码,编码,字节[]) (System.Text) [ ^ ]。 If you want UTF-16BE you have to use the Encoding.BigEndianUnicode Property (System.Text)[^]. For conversion use the Encoding.Convert Method (Encoding, Encoding, Byte[]) (System.Text)[^].// EDIT: Changed to use TF-8 and added output for console applicationstring myString = "यूनिकोड ";// Use UTF-8 if the source string is UTF-8 encodedbyte [] input = System.Text.Encoding.UTF8.GetBytes(myString);byte [] result = System.Text.Encoding.Convert(Encoding.UTF8, Encoding.BigEndianUnicode, input);// Use Unicode if the source string is UTF-16LE encoded (the default Windows encoding)//byte [] input = System.Text.Encoding.Unicode.GetBytes(myString);//byte [] result = System.Text.Encoding.Convert(Encoding.Unicode, Encoding.BigEndianUnicode, input);foreach (var utf16BEbyte in result) Console.Write("{0:X2} ", utf16BEbyte);Console.WriteLine();Console.ReadKey(); 输出: Output:09 2F 09 42 09 28 09 3F 09 15 09 4B 09 21 00 20 这篇关于我想在ASP.NET MVC中获得UTF-16BE字符串代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 08:49