简体   繁体   中英

strcpy in Symbian?

I am looking for a strcpy equivalent in Symbian. I do not wanna use the strcpy function from stdlib.

Here is what I wanna do:

char name[128];
TBuf8 aName = _L("Test");

strncpy( name, aName.Ptr(), 127 );
*( name + MAX_FILENAME_LEN ) = 0;   

So basically I wanna copy a TBuf8 to an char array. Is there a proper way to do that in Symbian? aName has to be of type char!

Thanks

Like this:

TInt size = aName.Size() <= 127 ? aName.Size() : 127;
Mem::Copy(name, aName.Ptr(), size);
name[size] = 0;

But beware that on unicode builds, TBuf8 strings are hard to come by, so there may be more to it than this.

char name[128];
TBuf8 name_buf = _L("Test");
TPtr8 name_ptr = TPtr8(name,sizeof(name));
name_ptr = aName;
name_ptr.ZeroTerminate(); //if it supposed to be a zeroterminated string. 

All text processing in symbian is easier if you learn to think in descriptors.

The ZeroTerminate call should obviously not be used if the TBuf8 contains binary data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM