function my_strcasecmp( a, b ){if((a+'').toLowerCase() > (b+'').toLowerCase()) return 1if((a+'').toLowerCase() < (b+'').toLowerCase()) return -1return 0}
<!doctype html><html>
<head><script>// 1st way
var a = "apple";var b = "APPLE";if (a.toUpperCase() === b.toUpperCase()) {alert("equal");}
//2nd way
var a = " Null and void";document.write(a.search(/null/i));</script></head>
</html>
$("#btnGuess").click(guessWord);
function guessWord() {
var letter = $("#guessLetter").val();var word = 'ABC';var pattern = RegExp(letter, 'gi'); // pattern: /a/gi
var result = word.match(pattern);alert('Ignore case sensitive:' + result);}
var a = "hello";var b = "HeLLo";var c = "world";
if (a.equalIgnoreCase(b)) {document.write("a == b");}if (a.equalIgnoreCase(c)) {document.write("a == c");}if (!b.equalIgnoreCase(c)) {document.write("b != c");}
输出将是:
"a == b""b != c"
String.prototype.equalIgnoreCase = function(str) {return (str != null &&typeof str === 'string' &&this.toUpperCase() === str.toUpperCase());}
var a = "hello";var b = "HeLLo";var c = "world";
if (a.equalIgnoreCase(b)) {document.write("a == b");document.write("<br>");}if (a.equalIgnoreCase(c)) {document.write("a == c");}if (!b.equalIgnoreCase(c)) {document.write("b != c");}
function toLower(a){
let c = "";
for(let i = 0;i<a.length;i++){
let f = a.charCodeAt(i);if(f < 95){
c += String.fromCharCode(f+32);}else{
c += a[i];}}
return c;}function compareIt(a,b){
return toLower(a)==toLower(b);
}console.log(compareIt("An ExamPlE" , "an example"));