PC Review


Reply
Thread Tools Rate Thread

convert utf8 string for label

 
 
Chance Hopkins
Guest
Posts: n/a
 
      4th Jun 2005
I have an app that uses a socket to grab some data and ASCII encodes it to
store in a file.

Some times the data is supposed to be utf8 and start with =?Utf-8? when I
view it with notepad.

I'm trying to turn it back into the original text like so:

----------------------------------


if(myString.StartsWith("=?Utf-8?"))
{

//SOMEWHERE IN THESE TWO LINES IS THE ISSUE

byte[] temp = System.Text.ASCIIEncoding.Convert(System.Text.Encoding.UTF8,
System.Text.Encoding.ASCII,
System.Text.ASCIIEncoding.ASCII.GetBytes(currentMsg.Subject));
lblSubject.Text = "Subject: " +
System.Text.Encoding.ASCII.GetString(temp,0,temp.Length);

temp = null;
}
else
lblSubject.Text = myString;

----------------------------------

I just don't understand which encoding I have.

When I GetBytes, should it be ascii or utf8? (I think ascii)

When I Convert, am I going from ascii to utf8 or utf8 to ascii?


Can someone point me in the right direction, please.

Thanks.


 
Reply With Quote
 
 
 
 
Sergey Bogdanov
Guest
Posts: n/a
 
      4th Jun 2005
As I correctly understand you you are talking about "encoded-words" (RFC
2047) that has the following format:

encoded-word = "=?" charset "?" encoding "?" encoded-text "?="

You should distinguish parsing for different encoding:
q - for quoted printable
b - base64

You can read more information about that formats in RFC2047. For example
base64-encoded text could be transformed back using the following code:

string decodedText =
Encoding.GetEncoding(charset).GetString(Convert.FromBase64String(encoded-text));

Long time ago I was writing .NET POP3 client that has parser of all that
stuff, maybe you can find here some useful code snippets:
http://sf.net/projects/nmailunit/

--
Sergey Bogdanov
http://www.sergeybogdanov.com


Chance Hopkins wrote:
> I have an app that uses a socket to grab some data and ASCII encodes it to
> store in a file.
>
> Some times the data is supposed to be utf8 and start with =?Utf-8? when I
> view it with notepad.
>
> I'm trying to turn it back into the original text like so:
>
> ----------------------------------
>
>
> if(myString.StartsWith("=?Utf-8?"))
> {
>
> //SOMEWHERE IN THESE TWO LINES IS THE ISSUE
>
> byte[] temp = System.Text.ASCIIEncoding.Convert(System.Text.Encoding.UTF8,
> System.Text.Encoding.ASCII,
> System.Text.ASCIIEncoding.ASCII.GetBytes(currentMsg.Subject));
> lblSubject.Text = "Subject: " +
> System.Text.Encoding.ASCII.GetString(temp,0,temp.Length);
>
> temp = null;
> }
> else
> lblSubject.Text = myString;
>
> ----------------------------------
>
> I just don't understand which encoding I have.
>
> When I GetBytes, should it be ascii or utf8? (I think ascii)
>
> When I Convert, am I going from ascii to utf8 or utf8 to ascii?
>
>
> Can someone point me in the right direction, please.
>
> Thanks.
>
>

 
Reply With Quote
 
Chance Hopkins
Guest
Posts: n/a
 
      4th Jun 2005

"Sergey Bogdanov" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> As I correctly understand you you are talking about "encoded-words" (RFC
> 2047) that has the following format:
>
> encoded-word = "=?" charset "?" encoding "?" encoded-text "?="



YES. "Message Header Extensions" Appears to be it. Thank you. I will start
reading.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
String with UTF8 in it? Jeff Microsoft Dot NET 1 25th Mar 2009 06:30 PM
how can I convert (char)02 into UTF8 string Daniel Rimmelzwaan Microsoft C# .NET 3 1st Apr 2005 04:53 AM
how to convert a UTF8 string to Unicode with C# =?Utf-8?B?S2VtcHRvbg==?= Microsoft Dot NET Compact Framework 2 9th Jul 2004 05:56 PM
how convert contents of string variable to label id tony collier Microsoft ASP .NET 1 11th Jan 2004 11:59 PM
Re: convert UTF8 string to UTF16 Jon Skeet Microsoft C# .NET 0 22nd Jul 2003 07:24 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:23 AM.