View Full Version : Can indexOf("text") be made case insensitive?
peterinwa
03-18-2003, 06:09 AM
I just needed a simple search routine but it can't be case sensitive. Is there a way around indexOf being case sensitive?
why don't you try something like (assuming that the string you are searching is permString, and the string you are searching for is permInput):
var searchString = permString.lowercase();
var searchInput = permInput.lowercase();
if (searchString.indexOf(searchInput)!=-1)
alert("found");
I don't know if the lowercase() and uppercase() functions are the exact stuff, but I know there are ways to convert. Anyone?
peterinwa
03-18-2003, 07:14 AM
I couldn't believe how easy it was to make a simple search capability for my long drop down menus (hundreds of items to scroll through) but I hadn't thought ahead (usually don't which is half the fun!) about case.
Your idea worked great, though I used toLowerCase().
My problem is that when I get stuck I never know where to look in my book. That's why this forum is so helpful.
Thanks so much.
liorean
03-18-2003, 08:25 AM
Otherwise, you can use regular expressions instead...
var indexString=str.search(/your text/i);
See my tutorial about regex on wsabstract (http://www.wsabstract.com/javatutors/redev.shtml) or the same tutorial on a single page on eVolt (http://www.evolt.org/article/Regular_Expressions_in_JavaScript/17/36435/index.html).
larson311
03-24-2009, 08:35 PM
Could I do this:
var halfURL = ptmLinkURL.substring(ptmLinkURL.indexOf(/"/tod/"/i)+5);
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.