-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.

1

4 Answers 4

2

What about

unichar aCharacter = [string characterAtIndex: charIndex];
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

0

By using toCharArray() method See this

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

Comments

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.