ios - NSPredicate filter array using all characters before delimiter -


i filtering using

self.searcharray.removeall(keepcapacity: false) let searchpredicate = nspredicate(format: "self contains[c] %@", searchcontroller.searchbar.text!) let array = (array(examplearray) nsarray).filteredarrayusingpredicate(searchpredicate) self.searcharray = array as! [string] 

it filtering whole string, however, want filter using characters exist before delimiter. example:

each array value has delimiter "$%^"

example array contains [abc$%^12], [efg$%^32], [tyh$%^77]

i want filtering include on characters before $%^ abc, efg, , tyh

you can without using nspredicate. stub:

let searchbartext = "h" let examplearray = ["abc$%^12", "efg$%^32", "tyh$%^77"]  let searchresults = examplearray.filter {     let components = $0.componentsseparatedbystring("$%^")     return components[0].containsstring(searchbartext) } 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -