I am trying to find if an image has in its source name noPic
which can be in upper or lower case.
var noPic = largeSrc.indexOf("nopic");
Should I write :
var noPic = largeSrc.toLowerCase().indexOf("nopic");
But this solution doesn't work...
No, there is no case-insensitive way to call that function.
Yes, the String. indexOf() methods are all case-sensitive.
The indexOf() method returns the index number where the target string is first found or -1 if the target is not found. Like equals(), the indexOf() method is case-sensitive, so uppercase and lowercase chars are considered to be different.
You can use regex with a case-insensitive modifier - admittedly not necessarily as fast as indexOf.
var noPic = largeSrc.search(/nopic/i);
No, there is no case-insensitive way to call that function. Perhaps the reason your second example doesn't work is because you are missing a call to the text()
function.
Try this:
var search = "nopic"; var noPic = largeSrc.text().toLowerCase().indexOf(search.toLowerCase());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With