Reputation: 137
Hy,
i want to decode a string which contain xml data in .net but that string was encoded in java
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
System.Text.Decoder utf8Decode = encoder.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(data);
int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount];
utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
result = new String(decoded_char);
return result;
i have written that code but it throw error. Thanks in Advance.
Upvotes: 0
Views: 459
Reputation: 1500105
Assuming it really is UTF-8 which is then base64-encoded, you should just be able to write:
byte[] binary = Convert.FromBase64String(data);
string text = Encoding.UTF8.GetString(binary);
However, it sounds like it wasn't base64-encoded to start with - if you've already got it as text, you should be able to use it without any extra work.
Upvotes: 2