objective c - Index of a character from the NSString in iOS -
i have nsstring example "this question"
.i want find indices of character/substring "i"
ie in case if index starts 0
,then want 2,5,16
answer.
the other answer bit of overkill. why don't iterate on characters this:
nsstring *x = @"this question"; (nsuinteger i=0;i<[x length];i++) { if ([x characteratindex:i]=='i') { nslog(@"found: %d", i); } }
it outputs positions:
found: 2 found: 5 found: 16
Comments
Post a Comment