From: Joseph M. Newcomer on 1 Oct 2009 23:19 for(int i = 0; i < buffer.GetSize(); i++) if(buffer[i] == 0x00) buffer[i] = 0x01; What is so hard about this? This is pretty elementary C programming! If you want to do it more along the "hard way" read about the MultiByteToWideChar API (and see my essay on my MVP Tips site on CString techniques) joe On Thu, 1 Oct 2009 15:09:07 -0400, "Eddards" <eddards(a)verizon.net> wrote: >I also need to replace any 0x00 (NULL) chars with 0x01 when copying to the >CString >Is this possible ? > >"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? >> >> > 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 2 Oct 2009 00:58 You can just create a CString variable then use a loop through the CByteArray assigning each item to the string. Tom "Eddards" <eddards(a)verizon.net> wrote in message news:--ednVzMMdF1YVnXnZ2dnUVZ_s-dnZ2d(a)giganews.com... > 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 > >
From: Tom Serface on 2 Oct 2009 00:59 If you do the loop you can check for that character or any other. Unless you're doing this a lot or the string is incredibly long I think you'll find this happens almost instantly. Tom "Eddards" <eddards(a)verizon.net> wrote in message news:SJGdnTCm-fvOY1nXnZ2dnUVZ_gqdnZ2d(a)giganews.com... >I also need to replace any 0x00 (NULL) chars with 0x01 when copying to the >CString > Is this possible ? > > "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 2 Oct 2009 07:45 I tried copying the buffer with a loop like you show below. It took over a minute to process all 4,000,000 bytes. Dont know why it should take so long. "Joseph M. Newcomer" <newcomer(a)flounder.com> wrote in message news:57sac5hc63e673ijs0fdttud2annvadrno(a)4ax.com... > for(int i = 0; i < buffer.GetSize(); i++) > if(buffer[i] == 0x00) > buffer[i] = 0x01; > > What is so hard about this? This is pretty elementary C programming! > > If you want to do it more along the "hard way" read about the > MultiByteToWideChar API (and > see my essay on my MVP Tips site on CString techniques) > > joe > On Thu, 1 Oct 2009 15:09:07 -0400, "Eddards" <eddards(a)verizon.net> wrote: > >>I also need to replace any 0x00 (NULL) chars with 0x01 when copying to the >>CString >>Is this possible ? >> >>"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? >>> >>> >> > Joseph M. Newcomer [MVP] > email: newcomer(a)flounder.com > Web: http://www.flounder.com > MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Eddards on 2 Oct 2009 08:23 This is what I have. The size of the file read into buffer was 4.6mb Why does it take so long to run through? (over a minute). int i; CString CipStr; for (i=0; i<buffer.GetSize(); i++){ if (buffer[i] == 0x00) buffer[i] = 0x01; CipStr += buffer[i]; } "Eddards" <eddards(a)verizon.net> wrote in message news:KpidnfDBIMVReljXnZ2dnUVZ_uOdnZ2d(a)giganews.com... >I tried copying the buffer with a loop like you show below. > It took over a minute to process all 4,000,000 bytes. > Dont know why it should take so long. > > > "Joseph M. Newcomer" <newcomer(a)flounder.com> wrote in message > news:57sac5hc63e673ijs0fdttud2annvadrno(a)4ax.com... >> for(int i = 0; i < buffer.GetSize(); i++) >> if(buffer[i] == 0x00) >> buffer[i] = 0x01; >> >> What is so hard about this? This is pretty elementary C programming! >> >> If you want to do it more along the "hard way" read about the >> MultiByteToWideChar API (and >> see my essay on my MVP Tips site on CString techniques) >> >> joe >> On Thu, 1 Oct 2009 15:09:07 -0400, "Eddards" <eddards(a)verizon.net> wrote: >> >>>I also need to replace any 0x00 (NULL) chars with 0x01 when copying to >>>the >>>CString >>>Is this possible ? >>> >>>"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? >>>> >>>> >>> >> Joseph M. Newcomer [MVP] >> email: newcomer(a)flounder.com >> Web: http://www.flounder.com >> MVP Tips: http://www.flounder.com/mvp_tips.htm > >
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: FTPFindFirstFile unicode Next: AfxConnectionAdvise: No events fired |