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.
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.
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);
Convert it to 1252:
Encoding w1252 = Encoding.GetEncoding(1252);
byte[] output = Encoding.Convert(utf8, w1252, inputStr);
Get the string back:
w1252.GetString(output);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With