How to use a wildcard when searching a dataset

Here is some code that I'm using:

Search_btn.onPress = function() {
      if (this._parent.ReasonCode_ds.hasSort("Category")) {
      var SearchID:String = null;
      if (this._parent.ReasonCode_ds.findFirst([this._parent.Search_txt.text])) {
       SearchID = this._parent.ReasonCode_ds.getItemId();
      } else {

I want to be able to use a wild card when entering text into the --- Search_txt --- component. (i.e. "Lost *")

So, if I have multiple instances in the dataset of the word "Lost" and I want to do a search for all instances normally I would use something like "Lost *", however for some reason if I enter "Lost" or "Lost *" the search fails. I have to put in the exact phrase that is in the dataset before I get a successful search (i.e. "Lost Keys") if "Lost Keys" is one of the items in the data set then the search works.

I sure hope someone out there can help. It doesn't seem logical to have to do a search for an exact phrase when the user may not know what the exact phrase is in the dataset!

LVL 21
Who is Participating?
BillystyxConnect With a Mentor Commented:
try using indexof

myString  .indexOf(  substring,  [ startIndex ] )

gemartiAuthor Commented:
Thanks Billystyx.....

I'm not really sure I follow your suggestion.

If I use the myString.indexOf(string,index) method then It looks like I'm have to iterate through each dataSet record, store the record to a string variable, evaluate for a match then store the index value to another variable. That seems a bit too time consuming. Is that what you are suggesting I do?

I can try, but if there is a better solution out there, I'd love to see it.
It is the only way I am aware of, gemarti. Hope it is enough to work for you.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.