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

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
RXN0aW1hZG8gY2xpZW50ZSwNCg0KU2llbmRvIGxhcyAxMjoyMCBwLm0uLCBzZSBoYSBmaW5h
bGl6YWRvIGxhIGFjdHVhbGl6YWNpw7NuIGRlbCBzaXN0ZW1hIElNUE8gQ09NRVggVkkuDQpE
aWNoYSBhY3R1YWxpemFjacOzbiBhZmVjdGFiYSBlbCBzaWd1aWVudGUgcmVxdWVyaW1pZW50
byB5L28gbWVqb3JhDQoNCioqKiAgICAgSUQgQU5QV09SS1MgICAgICoqKiAgICAgVmVudGFu
YSAgICAgKioqICAgICBEZXNjcmlwY2nDs24gICAgICoqKg0KKioqICAgICAzMzMzICAgICAq
KiogICAgIE9yZGVuIGRlIGNvbXByYSAgICAgKioqICAgICBQcnVlYmEgaW5mb3JtZSBhY3R1
YWxpemFjacOzbiAgICAgKioqDQoNClNvbGljaXRhbW9zIGRpc2N1bHBhciBsb3MgaW5jb252
ZW5pZW50ZXMgY2F1c2Fkb3MgcHJvZHVjdG8gZGUgZXN0YSBhY3R1YWxpemFjacOzbi4NCg0K
RGVwYXJ0YW1lbnRvIGRlIHNlcnZpY2lvIGFsIGNsaWVudGUNCkFOUFdPUktTIFMuQQ0Kc2Fj
QGFucHdvcmtzLmNsIHRlbMOpZm9ub3MgNjM1IDAwMTkgLSA1NzAgODgwMCAtIDY2NSA3OTM5DQo=

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

1 solution

Yes you can. This is base64, you can convert it using the method System.Convert.FromBase64String, see http://msdn.microsoft.com/en-us/library/system.convert.frombase64string.aspx[^].

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:
C#
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.

—SA
 
Share this answer
 
Comments
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?
--SA
pepito del puerto 14-Jun-11 16:55pm    
Thanks I was wrong int the input string I was sending this

=?utf-8?B?QWN0dWFsaXphY2nDs24gZGUgYXBsaWNhY2nDs24=?=

But I realize that I need to send it was this

QWN0dWFsaXphY2nDs24gZGUgYXBsaWNhY2nDs24=

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 http://en.wikipedia.org/wiki/Quoted-printable, 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.
--SA

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