ios - How to calculate same substring from given entire NSString -
i wan calculate total white space in given string.if total white space more 1 want replace 2nd number of space "\n"
for example: my string : "i iphone" . string contains 3 space. want o/p "i \niphone".
this example. string not static. give string dynamic how can implement ??
thanks in advance
nsstring *givenstring = @"i iphone ok"; nsarray *stringarray = [givenstring componentsseparatedbystring:@" "]; nsstring *string = @""; (int = 0; i<stringarray.count; i++) { string = i==2 ? [nsstring stringwithformat:@"%@\n%@",string,stringarray[i]] : [nsstring stringwithformat:@"%@ %@",string,stringarray[i]]; } nslog(@"%@",string);
hope helps!
Comments
Post a Comment