0

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.

3
  • 6
    For the love of all that is binary please provide the error. Commented Oct 31, 2011 at 15:14
  • The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters. Commented Oct 31, 2011 at 15:15
  • @jats: Then that sounds like it's not base64 to start with - what made you think it was? Commented Oct 31, 2011 at 15:16

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.