#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    1
    Rep Power
    0

    Convert NSString to char array


    I have a very long String but want to convert it to a char array, something like unsigned char[4]. for example:
    NSString *str = "Thisisaverylongstringofstringsjoinedtogether";
    unsigned char c[4] = str;

    I hope someone understands what i want and help me out. Thanks
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    10
    Rep Power
    0
    NSString * aString = @"This is a string";
    char const * charArray = [aString UTF8String];
  4. #3
  5. No Profile Picture
    Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    4
    Rep Power
    0
    Emma has given the right answer.

    If your string is encoded with something other than UTF-8, you could also use -[NSString cStringUsingEncoding:]
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2011
    Posts
    122
    Rep Power
    0

    The solutions is following.


    Hi dear

    Yes, We can convert the NSString to NSArray.
    There is predefined function for doing this operation.
    Following will help:
    - (NSArray *)componentsSeparatedByStringNSString *)separator
    - (NSString *)componentsJoinedByStringNSString *)separator

    Thanks
    Diya

IMN logo majestic logo threadwatch logo seochat tools logo