how to convert CString to Bytes

被刻印的时光 ゝ 提交于 2020-02-02 15:29:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!