Showing posts with label NSString stringWithUTF8String example. Show all posts
Showing posts with label NSString stringWithUTF8String example. Show all posts

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
A 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];

Saturday, May 14, 2011

NSString stringWithUTF8String example

stringWithUTF8String:

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

Important: Raises an exception if bytes is NULL.
Return Value of stringWithUTF8String
A string created by copying the data from bytes.

Example of [NSString stringWithUTF8String]

Following code fragment shows how to use the method. The proper way to create NSString that contains unicode characters is to use stringWithUTF8String and the \u#### escape sequence, like this:
NSString *aString = [NSString stringWithUTF8String:"To be continued\u2026"];