From: Eddards on 1 Oct 2009 10:18 I am using VC6. Is there a way to copy a CByteArray to a CString?
From: David Lowndes on 1 Oct 2009 11:11 >Is there a way to copy a CByteArray to a CString? Something like this: CByteArray ba; ba.Add('H'); ba.Add('e'); ba.Add('l'); ba.Add('l'); ba.Add('o'); CStringA str( reinterpret_cast<LPCSTR>( ba.GetData() ), ba.GetSize() ); Dave
From: Joseph M. Newcomer on 1 Oct 2009 11:09 Does the CByteArray contain any embedded NUL characters? What is the character encoding used in the CByteArray (ANSI, Unicode UTF-8, Unicode UTF-16?) For example, if I have a message from an embedded controller (ANSI), then I would do CByteArray msg; .... msg.SetSize(SOME_VALUE_HERE); ReadDevice(msg); .... // I could do this CStringA text((LPCSTR)msg.GetData()); CString result(text); return result; Note that this works correctly in Unicode and ANSI builds. In the above example, the byte array is a NUL-terminated sequence of 8-bit characters. But you need to say a *lot* more than you did about what is in the CByteArray! joe On Thu, 1 Oct 2009 10:18:24 -0400, "Eddards" <eddards(a)verizon.net> wrote: >I am using VC6. >Is there a way to copy a CByteArray to a CString? > Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Tom Serface on 1 Oct 2009 12:49 Just to add to what the others have said, it might be worth it to do a small loop (through the array) and add each character to the CString using += or SetAt() checking for nulls in the array. I don't think there is a restriction on the nulls nad it might goof up your string (unless that's what you intend of course). Tom "Eddards" <eddards(a)verizon.net> wrote in message news:9fGdnWZaLPg3J1nXnZ2dnUVZ_u6dnZ2d(a)giganews.com... >I am using VC6. > Is there a way to copy a CByteArray to a CString? > >
From: Eddards on 1 Oct 2009 15:03 As I said, I am using VC6 and CStringA doesnt work "Joseph M. Newcomer" <newcomer(a)flounder.com> wrote in message news:33h9c59jt650o15tei2qq5gbfbje5ghj32(a)4ax.com... > Does the CByteArray contain any embedded NUL characters? What is the > character encoding > used in the CByteArray (ANSI, Unicode UTF-8, Unicode UTF-16?) > > For example, if I have a message from an embedded controller (ANSI), then > I would do > > CByteArray msg; > ... > msg.SetSize(SOME_VALUE_HERE); > ReadDevice(msg); > ... > // I could do this > > CStringA text((LPCSTR)msg.GetData()); > CString result(text); > return result; > > > Note that this works correctly in Unicode and ANSI builds. > > In the above example, the byte array is a NUL-terminated sequence of 8-bit > characters. > > But you need to say a *lot* more than you did about what is in the > CByteArray! > joe > > On Thu, 1 Oct 2009 10:18:24 -0400, "Eddards" <eddards(a)verizon.net> wrote: > >>I am using VC6. >>Is there a way to copy a CByteArray to a CString? >> > Joseph M. Newcomer [MVP] > email: newcomer(a)flounder.com > Web: http://www.flounder.com > MVP Tips: http://www.flounder.com/mvp_tips.htm
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: FTPFindFirstFile unicode Next: AfxConnectionAdvise: No events fired |