Click here to Skip to main content
15,747,766 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I read it like this
Const fichero As String = "C:\utf.eml"
Label1.Text = ""
Dim texto As String
Dim lector As New StreamReader(fichero,Encoding.Default)
texto = lector.ReadToEnd()

and print it I see something like this:
Subject: =?utf-8?B?QWN0dWFsaXphY2nDs24gZGUgYXBsaWNhY2nDs24=?=
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64
X-EsetId: 7445FB28926891696B43FB7D903DD1

What can I do to see this like a normal string??
Updated 13-Jun-11 7:04am

1 solution

Yes you can. This is base64, you can convert it using the method System.Convert.FromBase64String, see[^].

This will give you array of byte. Now you need to interpret this array as a string assuming known encoding using appropriate encoding class, for example, UTF8.

Step-by-step, all together:
string Utf8StringFromBase64(string base64) {
    byte[] bytes = System.Convert.FromBase64String(base64);
    System.Text.Encoding encoding = new System.Text.UTF8Encoding();
    char[] chars = encoding.GetChars(bytes);
    return new string(chars);

As System.Text.Encoding is a base class for all encodings, the code for different encodings will differ only in constructor.

Share this answer
pepito del puerto 13-Jun-11 16:25pm    
I try with this but, launches a FormatException

Private Function transformarADatoLegible(ByVal text As String) As String

Dim datosByte As Byte() = Convert.FromBase64String(text)
Dim codificador As Encoding = New UTF8Encoding()

Dim caracteres = codificador.GetChars(datosByte)

Return New String(caracteres)
End Function

what am i doing wrong?
Sergey Alexandrovich Kryukov 14-Jun-11 13:27pm    
Looks OK... Exception in what line, what's on input? Maybe not valid base64?
pepito del puerto 14-Jun-11 16:55pm    
Thanks I was wrong int the input string I was sending this


But I realize that I need to send it was this


Now when I was reading a mail I found something like this
Subject: AsuntoPrueba =?UTF-8?Q?=C3=A1=C3=A9=C3=AD=C3=B3=C3=BA?=

And looks like a different type of encode, I google it and found that is a Quoted-Printable encoding so, I dont know what to do

Help Please
Sergey Alexandrovich Kryukov 17-Jun-11 23:36pm    
Looks familiar... Maybe "quoted printable"?
See, look at the links from this page, search internet -- will find out how to code/decode it. There is a lot of material with the code, including C# or VB.NET.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900