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.
-
Possible duplicate: [convert nsstring into char array][1] [1]: stackoverflow.com/questions/3581532/…user813891– user8138912012-06-01 08:50:21 +00:00Commented Jun 1, 2012 at 8:50
Add a comment
|
4 Answers
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];
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
By using toCharArray() method See this
String str="000000000000000000111111111111111111111111000000";
char[] cr=str.toCharArray();
System.out.println(cr[18]);//output:1