Convert CString to Binary and Binary to CString
-
How can I convert a CString variable to a binary string, so that I can write it to the text file in binary form and Read CString form? i am converting CString to Binary like this.
CString strRet;
CString strname="ABCDEF";for (int i = 0; i < strname.GetLength(); ++i) {
CString str; str.Format("%2.2x", strname\[i\]); strRet += str;
}
AfxMessageBox(strRet);But i don't know how to convert this Binary values to CString? Plz help me:rose:
-
How can I convert a CString variable to a binary string, so that I can write it to the text file in binary form and Read CString form? i am converting CString to Binary like this.
CString strRet;
CString strname="ABCDEF";for (int i = 0; i < strname.GetLength(); ++i) {
CString str; str.Format("%2.2x", strname\[i\]); strRet += str;
}
AfxMessageBox(strRet);But i don't know how to convert this Binary values to CString? Plz help me:rose:
Your function merely transforms the original string in another one, the latter containing the character codes of the former one, represented as two-digits hexadecimal values. What do you want to do, really? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
How can I convert a CString variable to a binary string, so that I can write it to the text file in binary form and Read CString form? i am converting CString to Binary like this.
CString strRet;
CString strname="ABCDEF";for (int i = 0; i < strname.GetLength(); ++i) {
CString str; str.Format("%2.2x", strname\[i\]); strRet += str;
}
AfxMessageBox(strRet);But i don't know how to convert this Binary values to CString? Plz help me:rose:
-
How can I convert a CString variable to a binary string, so that I can write it to the text file in binary form and Read CString form? i am converting CString to Binary like this.
CString strRet;
CString strname="ABCDEF";for (int i = 0; i < strname.GetLength(); ++i) {
CString str; str.Format("%2.2x", strname\[i\]); strRet += str;
}
AfxMessageBox(strRet);But i don't know how to convert this Binary values to CString? Plz help me:rose:
in your code you can do easily this: CString strname="ABCDEF";//if Unicode use the macro => TEXT("ABCDEF") :cool: //no transforming needed AfxMessageBox(strname); writing and reading data have only to be compatible. There is a tiny MFC class for it: http://msdn.microsoft.com/en-us/library/aa314304(VS.60).aspx[^] try it out and step-debug in the sources.
Greetings from Germany
-
in your code you can do easily this: CString strname="ABCDEF";//if Unicode use the macro => TEXT("ABCDEF") :cool: //no transforming needed AfxMessageBox(strname); writing and reading data have only to be compatible. There is a tiny MFC class for it: http://msdn.microsoft.com/en-us/library/aa314304(VS.60).aspx[^] try it out and step-debug in the sources.
Greetings from Germany
KarstenK wrote:
";//if Unicode use the macro => TEXT("ABCDEF")
no, use TEXT() ( or _T() ) anytime you use CString with literals. if using CStringW, then prepend the literals with L, and if using CStringA, then don't do much as writing the literal like you normally do. _T() will extend to the unicode or ansi version depending on the compilation mode, so you don't have to bother about it.
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]