Sunday, May 12, 2013

NSString stringWithUTF8String example ios

[NSString stringWithUTF8String]
Returns a string created by copying the data from a given C array of UTF8-encoded bytes.
+ (id)stringWithUTF8String:(const char *)bytes
Parameters of [NSString stringWithUTF8String]
bytes
NULL-terminated C array of bytes in UTF8 encoding.

Important: Raises an exception if bytes is NULL.
Return Value of [NSString stringWithUTF8String]
A string created by copying the data from bytes.
Example of [NSString stringWithUTF8String]
- (void) deviceListenerCallback:(DeviceEventTypeDef)type data:(void*)data
{
    DeviceInfoDef* o = (DeviceInfoDef*)data;
    NSString *deviceName;
    if (o != NULL)
        deviceName = [NSString stringWithUTF8String:o->DeviceName];
    else
        deviceName = @"";
Example of [NSString stringWithUTF8String]
char t = 'A' + i;
char s[2]; s[0] = t; s[1] = '\0';
NSString* alphabetString = [NSString stringWithUTF8String: s];
Example of [NSString stringWithUTF8String]
NSString *str = @"Name: ";
NSString *name = [NSString stringWithUTF8String:user.name];
str = [str stringByAppendingString:name];