Saturday, May 18, 2013

NSString initWithUTF8String example ios


[NSString initWithUTF8String]

Returns an NSString object initialized by copying the characters a given C array of UTF8-encoded bytes.
- (id)initWithUTF8String:(const char *)bytes
Parameters
bytes
NULL-terminated C array of bytes in UTF-8 encoding. This value must not beNULL.

Important: Raises an exception if bytes is NULL.
Return Value of [NSString initWithUTF8String]
An NSString object initialized by copying the bytes from bytes. The returned object may be different from the original receiver.
Example of [NSString initWithUTF8String]
-(NSMutableArray *) getPaises {
    NSMutableArray * paises;
    paises = [[[NSMutableArray alloc] init] autorelease];
    while( get new row ) {
        NSString *aPais =  [[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)];
        [paises addObject:aPais];
        [aPais release];
    }
    return paises;
}
Example of [NSString initWithUTF8String]
char *tmp = sqlite3_column_text(statement, 1);
if (tmp == NULL)
    strRestaurantName = nil;
else
    strRestaurantName = [[NSString alloc] initWithUTF8String:tmp];
Example of [NSString initWithUTF8String]
const char* addressField_tmp = (const char*)sqlite3_column_text(compiledStatement, 0);

NSString *addressField = addressField_tmp == NULL ? nil : [[NSString alloc]           initWithUTF8String:addressField_tmp];