views:

253

answers:

4

i am actually tryin to convert a csharp code to c... below is the C# code..

CString data = "world is beautiful";    
Byte[] quote = ASCIIEncoding.UTF8.GetBytes(data);

in the above code... it converts the string into bytes..similarily is ther a way that i can convert it using C.. Can any body tell what wud be the quivalent code in C? Please help me guys

A: 

In C the char type is defined as one byte in memory. Hence storing your string as a char * would be equivalent to storing a byte array in C#.

Benjamin Dobell
The poster is asking how to encode a Unicode string as UTF-8.
Jonathan Feinberg
@Jonathan: Thats a harsh downvote. The original question didnt mention UTF8, it was just used as an example.
PaulG
A: 

Read this: link text

malvin
+2  A: 

Well CString is a C++ class so doing it in C is a little unlikely.

But if you wish to get it as a standard multi-byte encoded string then you can do the following

CString data    = "world is beautiful";
CStringA mbStr  = data;
char* bytes     = mbStr.GetString();
Goz
tanx for u reply..but still its reading it as an string but not as bytes..does it makes sense
kiddo
a char array IS an array of bytes. Just because you look in a debugger and it interprets it as a set of characters is neither here nor there. You DO have an array of bytes.
Goz
A: 

Hello,

I still didn't understand what is the right way to get a byte array of a unicode CString. Would you please explain?

thank you.

girl games