-1

I want to split the below string into sub string, string = 000000000000000000111111111111111111111111000000. How to split like we have 48 characters in the mentioned string? I want to separate each character into an array so that I can fetch the values based on the index.

halfer
  • 19,824
  • 17
  • 99
  • 186
Santosh Gurram
  • 1,007
  • 3
  • 13
  • 22
  • Possible duplicate: [convert nsstring into char array][1] [1]: http://stackoverflow.com/questions/3581532/convert-nsstring-into-char-array – Marco Pace Jun 01 '12 at 08:50

4 Answers4

2

What about

unichar aCharacter = [string characterAtIndex: charIndex];
JeremyP
  • 84,577
  • 15
  • 123
  • 161
1

If you want to retrieve a certain character you can use [(NSString *)string characterAtIndex:(int)index];

e.g. get the char at index 0

unichar character = [string characterAtIndex:0];

NSString characterAtIndex:

If you want to split the string into substrings then you can use the split/substring functions – substringFromIndex:, – substringWithRange: and – substringToIndex:. There are lots more methods which you can use as well. Have a look at the NSString dev reference

Thomas Clayson
  • 29,657
  • 26
  • 147
  • 224
0

By using toCharArray() method See this

String str="000000000000000000111111111111111111111111000000";
char[] cr=str.toCharArray();
System.out.println(cr[18]);//output:1
0

Using the blow code you can fetch the string with the index

NSMutableArray * stringArray = [[NSMutableArray alloc]init];
for (int i=0; i<yourString.length; i++) {
    [stringArray addObject:[NSString stringWithFormat:@"%c",[yourString characterAtIndex:i]]];
}
NSLog(@"string %@",stringArray);
Vignesh
  • 592
  • 6
  • 25