CoderZone.org

Category: >> JavaScript >> Case Insensitive Compare Bookmark and Share

<< lastnext >>

Snippet Name: Case Insensitive Compare

Description: Very handy javascript snippet that compares two strings in a case-insentive fashion.

Also see:
» SEO string generator
» Match all #RRGGBB or #RGB values i...
» Remove empty lines from a string o...
» Find first non-numeric character i...
» Read a web page directly in to a s...
» Multi-line variables and strings i...
» Convert a String to Title Case in ...
» Count all words in a string
» Count specific characters in a str...
» Create an array from comma separat...
» Convert Unix time string to a date...
» Easily Change Text To Lowercase
» Count Uppercase Letters In A String
» Neatly trim a string to a set numb...
» Search array elements for a substr...
» Add a period at the end of a strin...
» Count capital letters in a string
» Search All Words Of A String In my...
» Remove Extra Spaces From A String
» Get Query String with Javascript
» Create string by formatting an amo...
» Search PL/SQL for a string/ key va...
» INSTR (InString)
» SUBSTR (SubString)
» Generate unique strings of random ...
» String Functions: REVERSE
» String Functions: LENGTH
» String Functions: INSTR
» String Functions: CONCAT

Comment: (none)

Author: CoderZone
Language: JAVASCRIPT
Highlight Mode: JAVASCRIPT
Last Modified: December 03rd, 2010

<html>
<head>
 
<script type="text/javascript">
String.prototype.equalsIgnoreCase=myEqualsIgnoreCase;
String.prototype.equals=myEquals;
 
function myEquals(arg){
        return (this.toString()==arg.toString());
}
 
function myEqualsIgnoreCase(arg)
{               
        return (new String(this.toLowerCase())==(new
String(arg)).toLowerCase());
}
</script>
 
</head>
<body>
 
<script type="text/javascript">
var _Vals=new Array();
/* declare your string either way */
_Vals[0]=new String("ABCDEFGHIJK");
_Vals[1]="abcdefghijk";
_Vals[2]="defghijklmon";
 
/* This goes through all the examples. */
for(var i=0;i<_Vals.length;i++)
for(var j=0;j<_Vals.length;j++)
{
document.write("\""+_Vals[i]+"\".equals(\""+_Vals[j]+"\")"); document.write("=
"+_Vals[i].equals(_Vals[j])+"<BR>");
 
document.write("\""+_Vals[i]+"\".equalsIgnoreCase(\""+_Vals[j]+"\")");
document.write("= "+_Vals[i].equalsIgnoreCase(_Vals[j])+"<BR>");
 
}
</script>
</body>
</html>
 
 
 
 
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 10