objective c - spliting random strings in iphone -
i have string random numbers,
like "12345678912234"
i want split 4 parts, like,
string1 = 123
string2 = 456
string3 = 7891
string4 = 2234
anybody has idea??
i've tried using nsrange cannot it. may i'm using wrong.
i tried using substringtoindex
failed too. please me guys
-(nsstring *)splitstring:(nsstring *)string fromx:(int)x toy:(int)y { nsrange range = { x, y}; return [string substringwithrange:range]; } nslog([self splitstring:@"12345678912234" fromx:0 toy:3]); nslog([self splitstring:@"12345678912234" fromx:3 toy:3]); nslog([self splitstring:@"12345678912234" fromx:6 toy:4]); nslog([self splitstring:@"12345678912234" fromx:10 toy:4]);
just tested :) works fine. (just clarify: have named function incorrectly not toy how many characters want take in x).
Comments
Post a Comment