Convert a string?

  • Thread starter Thread starter G
  • Start date Start date
G

G

Hello,

I would like to convert
string "I am a fish" into a hex string if easy?

Fairly new to .NET and have looked on google etc without much luck.

Any help appreciated,

Gary.
 
What exactly do you mean by "convert...to a hex string?" Apparently, you are
referring to a string containing hexadecimal notation, but of what? A string
is a sequence of Unicode characters, unless it is in some other form of
encoding. At any rate, perhaps a statement of the purpose of this would
help.

--
HTH,

Kevin Spencer
Microsoft MVP

Help test our new betas,
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
How about something like this (needs checking since I threw it together
pretty fast):

static string Hex(string s)
{
byte[] b = System.Text.Encoding.UTF8.GetBytes(s);
string temp="";
string s2 = "";
int i;
for (i = 0; i < b.Length; i++)
{
temp = b.ToString("x2");
s2+= temp;
}
return s2;
}

--Peter
 
Maybe he wants something like a base64 representation of his string?

...ab
 
Abubakar said:
Maybe he wants something like a base64 representation of his string?

Well, base 64 isn't hex - but the same problem would occur: base64 is a
way of representing *binary* data as text, so how does the OP want to
convert the original text to binary in the first place?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top