×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    371

    Thumbs up How to convert Strings into byte array

    HI,
    Can we convert string to byte array in symbian c++ as we do lke java.Please help me if any body knows how to convert string into byte array?

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,169

    Re: How to convert Strings into byte array

    TBuf8 etc. are actually byte arrays already, so you could use [x] where x is zero based index to access the byte stored in the descriptor.

  3. #3
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    371

    Re: How to convert Strings into byte array

    Can we use that TBuf8 in double dimensional array as x[ ] [ ] .Please can u tel me how to use double dimensional byte array?Please

  4. #4
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,169

    Re: How to convert Strings into byte array

    Never used it that way, thougn you could try using for example pointer array with HBufC8, or something like CDesC8ArrayFlat with TBuf8.

  5. #5
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,752

    Re: How to convert Strings into byte array

    Quote Originally Posted by prathi View Post
    Can we use that TBuf8 in double dimensional array as x[ ] [ ] .Please can u tel me how to use double dimensional byte array?Please
    It is not possible. What would be the second dimension anyway? Java does not support such thing for its strings either.

  6. #6
    Regular Contributor
    Join Date
    Dec 2010
    Posts
    142

    Re: How to convert Strings into byte array

    Not possible with TBuf8. You should use real two dimensional byte array, e.g. TUint8 byteArray[10][30]

    If you absolutely need TBuf8 to store two dimensional array.,you should implement your own indexing logic (map two dimensional array index to one dimensional index to use with TBuf8).

  7. #7
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    371

    Re: How to convert Strings into byte array

    Hai,
    I am storing the values in HBufC8* requestdata;Now i want to test how we can display the requestdata ti byte array.

    I am using following code for the.requestdata->Des().Append(_L8("10"));

    requestdata->Des().Append(_L8("20112011"));

    LOGTXT("VALUE OF REQUESTDATA");
    LOGDES16(requestdata->Des());
    LOGDES16(requestdata[0].Des());
    LOGDES16(requestdata[1].Des());//here it crashes with user 23
    LOGDES16(requestdata[2].Des());
    LOGDES16(requestdata[3].Des());

    LOGDES16(requestdata[1].Des());//here it crashes with user 23 here it is crashing
    can u tel me y it is happening so?

  8. #8
    Super Contributor
    Join Date
    Aug 2005
    Location
    india
    Posts
    2,078

    Re: How to convert Strings into byte array

    Hi,

    This is the error reason

    23


    This panic is raised when any operation that moves or copies data to an 8 bit variant descriptor, causes the length of that descriptor to exceed its maximum length.

    It may be caused by any of the copying, appending or formatting member functions and, specifically, by the Insert(), Replace(), Fill(), Fillz() and ZeroTerminate() descriptor member functions. It can also be caused by the SetLength() function. See TDes8.

    descriptor copying issue from 8 bit to 16bit.

    Regards,
    Mateen Maldar
    "Whatever the mind can conceive and believe, the mind can achieve"

  9. #9
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,169

    Re: How to convert Strings into byte array

    thia case it is not actually that, it is the misunderstanding the HBufC would somehow be array of descriptors.. So what about trying to use it as a array of chars instead..

  10. #10
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    371

    Re: How to convert Strings into byte array

    The thing i need is HBufC8* requestdata; in which contents of requestdata->Des() has to be displayed in byte array as [].Please tel me how i can do this.I tried in many ways but dint get how to write in byte array.Please help me.

  11. #11
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,752

    Re: How to convert Strings into byte array

    Quote Originally Posted by symbianyucca View Post
    thia case it is not actually that, it is the misunderstanding the HBufC would somehow be array of descriptors.. So what about trying to use it as a array of chars instead..
    Misunderstanding of HBufC, pointers, arrays and 8/16-bit descriptors probably.

    Prathi: generally you should review these topic once more, what does pointer->something and pointer[x].something mean, why 0 works and 1 does not, etc.
    For your particular use case you may need (*pointer)[x], which is different from pointer[x]
    However if LOGDES16 logs a 16-bit descriptor, you need a 16-bit descriptor. While L8 is a 8-bit one, so requestdata seems to be a 8-bit one. You can allocate a HBufC and copy the data into it, like
    Code:
    HBufC *des16=HBufC::NewLC(requestdata->Length());
    des16->Des().Copy(*requestdata);
    LOGDES16(*des16);
    CleanupStack::PopAndDestroy(); // des16

Similar Threads

  1. How to convert image into byte array
    By dhiraj.deka in forum Mobile Java General
    Replies: 6
    Last Post: 2009-11-23, 09:23
  2. How to convert byte array to base64Binary?
    By mects in forum Mobile Java General
    Replies: 1
    Last Post: 2009-06-03, 06:17
  3. convert image to byte array
    By s4028469 in forum Symbian Media (Closed)
    Replies: 4
    Last Post: 2007-08-15, 11:07
  4. Convert wav to byte array?
    By SpaceCowboy in forum Mobile Java Media (Graphics & Sounds)
    Replies: 5
    Last Post: 2006-09-04, 09:25
  5. How to Convert mid to byte array?
    By returnti in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2003-05-09, 18:23

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×