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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -