Created
February 7, 2014 21:03
-
-
Save 06b/8871805 to your computer and use it in GitHub Desktop.
StartsWith(string suffix,bool ignoreCase), EndsWith(string suffix,bool ignoreCase) and Trim() :
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// string.StartWith implementation | |
String.prototype.StartsWith = function(prefix,ignoreCase) { | |
if( !prefix ) return false; | |
if( prefix.length > this.length ) return false; | |
if( ignoreCase ) { | |
if( ignoreCase == true ) { | |
return (this.substr(0, prefix.length).toUpperCase() == prefix.toUpperCase()); | |
} | |
} | |
return (this.substr(0, prefix.length) === prefix); | |
} | |
// string.EndsWith implementation | |
String.prototype.EndsWith = function(suffix,ignoreCase) { | |
if( !suffix ) return false; | |
if( suffix.length > this.length ) return false; | |
if( ignoreCase ) { | |
if( ignoreCase == true ) { | |
return (this.substr(this.length - suffix.length).toUpperCase() == suffix.toUpperCase()); | |
} | |
} | |
return (this.substr(this.length - suffix.length) === suffix); | |
} | |
// string.Trim implementation | |
String.prototype.Trim = function() { | |
return this.replace(/^\s+|\s+$/g, ''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment