all groups > flash actionscript > january 2004 >
You're in the

flash actionscript

group:

Can String.indexOf() ignore case?



Can String.indexOf() ignore case? quadrant6
1/27/2004 10:40:42 PM
flash actionscript: I have a simple search which takes what is in the text input box ans searches through an array trying to find a match.

I've found a nice and simple way but there is one problem - if the user enters "road" and the heading is "Road ..", it doesn't display a match. that is indexOf is case sensitive.

Is there a simple way around this ?


current code:


for(i=0; i<articles.length; i++) {
if(articles['heading'].indexOf(input_search.text) != -1
// display a hit
}
}




Re:Can String.indexOf() ignore case? jerome NO[at]SPAM STC
1/28/2004 4:27:51 AM
the best way to ensure case UNsensitivity is to convert both strings to be compaired to either lower or uppercase. as in :

var searchInput = input_search.text.toLowerCase();
var heading = articles['heading'].toLowerCase();

if(heading.indexOf(searchInput) != -1
// display a hit
}



check out the STC fontBrowser

STC Associates
AddThis Social Bookmark Button