ios - Getting a string in textfield before a specific string in the textfield -
so textfield has following text. @"a big tomato red."
i want word before "is".
when type
nsstring *somestring = [[textfield componentsseparatedbystring:@"is"]objectatindex:0];
i "a big tomato"
instead of "tomato"
. in app people type things before "is"
need string before "is"
. appreciate can get. *warning,
this difficult problem.
try this
nsstring *str = @"a big tomato red"; nsarray *arr = [str componentsseparatedbystring:@" "]; int index = [arr indexofobject:@"is"]; if(index > 1) nsstring *str_tomato = arr[index-1]; else //"is" first word of sentence
as per yvesleborg's comment
Comments
Post a Comment