问题
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
回答1:
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();
回答2:
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#.
来源:https://stackoverflow.com/questions/1650035/how-to-convert-cstring-to-bytes