Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to divide a string to a charecter wise?

I am having a string @"sairam". I need a characters separately and i need to store it into an ARRAY like

array = [@"s",@"a",@"i",@"r",@"a",@"m"];

how to do this give a loop like if i give a string it needs to divide charecters and store it into an array ...

thanks in advance...

like image 571
sairam Avatar asked Nov 20 '25 14:11

sairam


1 Answers

From http://www.idev101.com/code/Objective-C/Strings/split.html:

  NSMutableArray *characters = [[NSMutableArray alloc] initWithCapacity:[myString length]];
  for (int i=0; i < [myString length]; i++) {
      NSString *ichar  = [NSString stringWithFormat:@"%c", [myString characterAtIndex:i]];
      [characters addObject:ichar];
  }
like image 170
vinod Avatar answered Nov 23 '25 04:11

vinod



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!