String can be initialized by
var s = new String("endmemo.com"); var s = "endmemo.com";
var s = "endmemo.com"; var len = s.length; //s=11
String characters are indexed from 0 to
var s = "endmemo.com"; var x = s[2]; x = 'd'
var s = "endmemo.com"; var c = s.charAt(3); //c = 'm'
var s = "endmemo.com"; var c = s.charCodeAt(3); //c = 109
var s = new String("endmemo.com"); var p = s.indexOf('m') //p = 3 p = s.indexOf("g") //p = -1 p = s.indexOf("mo") //p = 5
var s = new String("endmemo.com"); var p = s.lastIndexOf('m') //p = 10 p = s.lastIndexOf("g") //p = -1 p = s.lastIndexOf("e") //p = 4
var s = "endmemo.com"; var s2 = arr.slice(2,5); //s2 is "dme" var s2 = arr.slice(2); //s2 is "dmemo.com"
var s = "endmemo.com"; var x = s.valueOf(); //x = "endmemo.com"
var s1 = "endmemo.com"; var s2 = "javascript"; var s3 = "tutorial"; var s = s1.concat(" ", s2, " ", s3); //s is "endmemo.com javascript tutorial"
var c = String.fromCharCode(109); // c = 'm'
var s = "endmemo.com"; var m = s.match(/.m/g); //m is an array returned m.valueOf(); //dm,em,om
var s = "endmemo.com R language tutorial"; var x = s.replace("R language","javascript"); //x is "endmemo.com javascript tutorial" var x = s.replace(/\sR.+ge\s/,"javascript"); //same result, using regular expression
var s = "endmemo.com"; var p = s.search("dm"); //p is 2 var p = s.search(/e.o/); //p is 4 var p = s.search(/\s\d/); //p is -1, not found
var s = "endmemo.com"; var arr = s.split("m"); //arr is ["end","e","o.co"] var arr = s.split("me"); //arr is ["end","mo.com"]
Click here to see how we read a textarea
and split the content into an array of lines by "\n" in function
var s = "endmemo.com"; var x = s.substr(2,2); //x="dm" var x = s.substr(2); //x="dmemo.com"
var s = "endmemo.com"; var x = s.substring(2,4); //x="dm" var x = s.substring(2); //x="dmemo.com"
var s = "endmemo.com"; var x = s.toUpperCase(); //x is "ENDMEMO.COM" var y = x.toLowerCase(); //y is "endmemo.com"
var s = "endmemo.com"; var x = s.constructor; //x = "function String() {[native code]}"
String.prototype.UpperFirst = function() { var res = ""; for (var i=0; i<this.length;i++) { if (i == 0 || this.charCodeAt(i-1) == 32) res += this[i].toUpperCase(); } return res; } var s = "end memo com"; var x = s.UpperFirst(); //x is "End Memo Com"