Strings from hell

  • Thread starter Thread starter Harold Skeggs
  • Start date Start date
H

Harold Skeggs

Hello, I'm hoping someone can point me in the right direction, or better
still, help me with a code snippet :)

I have the following text in a string:

"=?utf-8?B?UmHimaXDr+KBv2cgIEzimYLimYDimatpzrU=?="

I want to convert it to displayable characters, like this:

"Ra?ving L???ie"

I know I will lose non-displayable characters, and that's exactly what I
want to do with the input text but I don't know how to do it. Can anyone
give me some advice on how to go about achieving that goal, please? I'd be
very grateful as I'm a novice and this has had me stumped for two days.

I have both .NET 2003 and .NET 2005, but prefer to work in 2005, if that
helps.
 
So you basically want to only display certain ASCII values, so can't you
use chr.

Put the string in a loop and do

foreach(char c in s)
....print values that are <> n and n1
 
John A. Bailo said:
So you basically want to only display certain ASCII values, so can't
you use chr.

Put the string in a loop and do

foreach(char c in s)
....print values that are <> n and n1

Huh?

How do you propose that your code will translate the string
"=?utf-8?B?UmHimaXDr+KBv2cgIEzimYLimYDimatpzrU=?=" into the correct "Ra?ving
L???ie"?

Are you a linux-using idiot or something? Sheesh.
 
I can't make any sense out of your question either,
but it would help if you didn't post to both VB
and VB.Net. The groups with "dotnet" are for
..Net. The first group in your posting list is VB6
and under.
 
So you want to convert a UTF-8 encoded UNICODE string that is being
displayed as ASCII on screen into what it should show up as UNICODE on
screen? because thats sure as heck what i get out of what you wrote and the
whole "UTF-8" marker in it screams this is a UNICODE string broken into
ASCII... but you REALLY need to provide more information on what you want to
do.. showing a string and say turn it into this doesnt help many people
because that is way too vague. what is the formatting of the two strings...
i assume the intial one is UTF-8 based on its encoding marker... what is the
final format? basic UNICODE? if so look at the encode class in .NET

http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemTextEncodingClassGetEncodingTopic2.asp
 
and if that doesnt help you to figure out it on your own... convert the text
into a byte array... and use the encode.convert to convert it from one
format to another...
 
Harold ,

Please reply in a normall way to the people who respond to your questions

I for a fact would never reply with a answer , when the reaction that did
not solve your problem to another person is like that

And yes to answer your question in forehand ,,,, Yes i am stupid to ,,,even
though I do stupid stuff, this people who are supposed to have average
intelligence do really stupid stuff, and a lot of it. They also are unaware
of so many solutions to their problems. This, of course, makes me feel
smart. But am I? Or am I just surrounded by idiots?


regards

Michel Posseth [MCP]
 
m.posseth said:
Harold ,

Please reply in a normall way to the people who respond to your questions

I for a fact would never reply with a answer

My feelings exactly. Rudeness on newsgroups never pays, stupid or
unintelligible replies or not.

Scott
 
The following program will decode it (somehow):

static void Main(string[] args)
{
string encoded = "=?utf-8?B?UmHimaXDr+KBv2cgIEzimYLimYDimatpzrU=?=";
// eliminate leading =?utf-8?B? and trailing ?=
encoded = encoded.Substring(10, encoded.Length - 12);
// decode base 64
byte[] bytes = Convert.FromBase64String(encoded);
// convert to string
string decoded = System.Text.Encoding.UTF8.GetString(bytes);
// print
Console.WriteLine(decoded);
}

But I get a slightly different result. I get something like
Ra?iXg L???iY
where X looks like a superscript n and Y looks like greek epsilon.

I don't know how you will be able to make sense out of the result.

Bruno.
 
Harold said:
Oh, so you're stupid too.

That's the way to do it, Harold. Insult the people that try to help you.
You're way more likely to get assistance in the future after doing that.
 
Bruno Jouhier said:
The following program will decode it (somehow):

static void Main(string[] args)
{
string encoded = "=?utf-8?B?UmHimaXDr+KBv2cgIEzimYLimYDimatpzrU=?=";
// eliminate leading =?utf-8?B? and trailing ?=
encoded = encoded.Substring(10, encoded.Length - 12);
// decode base 64
byte[] bytes = Convert.FromBase64String(encoded);
// convert to string
string decoded = System.Text.Encoding.UTF8.GetString(bytes);
// print
Console.WriteLine(decoded);
}

But I get a slightly different result. I get something like
Ra?iXg L???iY
where X looks like a superscript n and Y looks like greek epsilon.

I don't know how you will be able to make sense out of the result.

I most certainly can. That is excellent work. Thank you very much. You are
worth your weight in gold. What I was missing was this...
// eliminate leading =?utf-8?B? and trailing ?=

It was a pleasure to get assistance from someone who knows what they're
doing instead of those who only pretend to know. Now I'm off to conquer the
world. Have a nice weekend, sir.

Regards,
Harold.
 
One other point, if you persist in posting in this NG, then we shall
start cross posting to dotnet NGs - which will make a real mess

With me being a right **** that can ruin your entire day with one
well-placed, incisive remark, I'm up for it.
 
Harold Skeggs said:
Bruno Jouhier said:
The following program will decode it (somehow):

static void Main(string[] args)
{
string encoded =
"=?utf-8?B?UmHimaXDr+KBv2cgIEzimYLimYDimatpzrU=?="; // eliminate
leading =?utf-8?B? and trailing ?= encoded =
encoded.Substring(10, encoded.Length - 12); // decode base 64
byte[] bytes = Convert.FromBase64String(encoded);
// convert to string
string decoded = System.Text.Encoding.UTF8.GetString(bytes);
// print
Console.WriteLine(decoded);
}

But I get a slightly different result. I get something like
Ra?iXg L???iY
where X looks like a superscript n and Y looks like greek epsilon.

I don't know how you will be able to make sense out of the result.

I most certainly can. That is excellent work. Thank you very much.
You are worth your weight in gold. What I was missing was this...
// eliminate leading =?utf-8?B? and trailing ?=

It was a pleasure to get assistance from someone who knows what
they're doing instead of those who only pretend to know. Now I'm off
to conquer the world. Have a nice weekend, sir.

Regards,
Harold.

Here it is, Bruno:

Dim sIn As String
Dim sOut As String

sIn = Encoding.UTF8.GetString( _
Convert.FromBase64String("UmHimaXDr+KBv2cgIEzimYLimYDimatpzrU="))

sOut = ""
For Each c As Char In sIn
sOut = sOut & Encoding.UTF8.GetChars(Encoding.ASCII.GetBytes(c))
Next

I now have two strings, one that displays correctly for systems that support
unicode and one that displays as I want it for systems that don't support
unicode.

Again, many thanks for your kind help.
 
now just learn now to treat people yourself... calling people linux idiots
or what not is stupid... especially since linux people work with UTF-8 and
base 64 a LOT more then windows people ever would...
 
Harold Skeggs said:
It was a pleasure to get assistance from someone who knows what they're
doing instead of those who only pretend to know. Now I'm off to conquer
the world.

Atta boy Harold!
Perhaps you'll make US President one day.
You have both the brains and the diplomacy!
 
With me being a right **** ....

I must commend you for heeding Socrates' wise recommendation, "Know
Thyself." I will follow up by suggesting you reinterpret it using the
biblical connotation of the active verb.
 
Ross said:
I must commend you for heeding Socrates' wise recommendation, "Know
Thyself." I will follow up by suggesting you reinterpret it using the
biblical connotation of the active verb.

Not agreeing or disagreeing with the comment, but *damn* that was
cleverly stated. :-)
 
Back
Top