Convert UTF7 to UTF8

How do I convert some very short text from UTF7 to UTF8? Wikipedia says:

  1. Express each Base64 code as the bit sequence it represents:
    AKMgIA → 000000 001010 001100 100000 001000 000000
  2. Regroup the binary into groups of sixteen bits, starting from the left:
    000000 001010 001100 100000 001000 000000 → 0000000010100011 0010000000100000 0000
  3. If there is an incomplete group at the end containing only zeros, discard it (if the incomplete group contains any ones, the code is invalid):
    0000000010100011 0010000000100000
  4. Each group of 16 bits is a character’s Unicode (UTF-16) number and can be expressed in other forms:
    0000 0000 1010 0011 ≡ 0x00A3 ≡ 16310

How do I make 000000 from an A? What is “bit sequence it represents”?

dim temp as string = Bin(EncodedPart.Left(1).AscByte)

makes a 1000001.

I think I got it:

dim s as String = "M"
dim i as Integer = s.AscByte - 65
dim t as String = "00000" + Bin(i)
t = t.Right(6)

A MemoryBlock would make short work of this.

Edit: I really shouldn’t post after just waking up. Disregard.

It means, “decode the Base64”. Try this:

var encoded as string = "AKMgIA"

var decoded as string = DecodeBase64( encoded ) // 00000000 10100011 00100000 00100000
var s as string = decoded.DefineEncoding( Encodings.UTF16BE )
s = s.ConvertEncoding( Encodings.UTF8 ) // £†

Edit: Corrected to UTF16BE.

1 Like