neevek
neevek

Reputation: 12148

How to convert part of a char array into an NSString*?

char arr[] = "abcdefg";
// I know I can do this
NSString *s = [[NSString alloc] initWithCString:arr encoding:NSUTF8StringEncoding];

If I want to convert part of the arr array into an NSString*? say cde rather then the whole string abcdefg? How do I achieve that?

Upvotes: 3

Views: 1886

Answers (1)

rob mayoff
rob mayoff

Reputation: 385998

NSString *s = [[NSString alloc] initWithBytes:arr + 2
    length:3 encoding:NSUTF8StringEncoding];

Upvotes: 4

Related Questions