将UTF8转换为Windows-1252 [英] Converting UTF8 to Windows-1252
本文介绍了将UTF8转换为Windows-1252的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个asp.net GET网络服务,该服务接受一个URL参数,运行一些逻辑,然后传回þ分隔的值列表.
I have an asp.net GET webservice that takes in a URL parameter, runs some logic, and then passes back a þ delimited list of values.
我遇到的问题是发出请求的服务使用的是Windows-1252编码,因此当将þ字符返回到请求计算机时,properly字符不能正确显示.我正在寻找一种将字符串从UTF8转换为Windows-1252并传递回去的快速方法.
The problem I have is the service making the request is using Windows-1252 encoding, so the þ character doesn't display properly when it's returned to the requesting machine. I'm looking for a quick way to convert a string from UTF8 to Windows-1252 to pass back.
推荐答案
将字符串inputStr
转换为字节数组:
Convert your string inputStr
to byte array :
byte[] bytes = new byte[inputStr.Length * sizeof(char)];
System.Buffer.BlockCopy(inputStr.ToCharArray(), 0, bytes, 0, bytes.Length);
将其转换为1252:
Encoding w1252 = Encoding.GetEncoding(1252);
byte[] output = Encoding.Convert(utf8, w1252, inputStr);
取回字符串:
w1252.GetString(output);
这篇关于将UTF8转换为Windows-1252的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文