KEMBAR78
Javascript strings | PPT
String
charAt() 
var str = "HELLO WORLD"; 
var res = str.charAt(0); 
// H
charCodeAt() 
var str = "HELLO WORLD"; 
var n = str.charCodeAt(0); 
/72
concat() 
var str1 = "Hello "; 
var str2 = "world!"; 
var res = str1.concat(str2); 
// Hello world
fromCharCode() 
var res = String.fromCharCode(65); 
// A
indexOf() 
var str = "Hello world, welcome to the 
universe."; 
var n = str.indexOf("welcome"); 
// 13
lastIndexOf() 
var str = "Hello planet earth, you are a 
great planet."; 
var n = str.lastIndexOf("planet"); 
// 36
match() 
var str = "The rain in SPAIN stays mainly 
in the plain"; 
var res0 = str.match(/ain/g); //global 
var res1 = str.match(/ain/gi); //global 
ignore case 
// ain,ain,ain 
// ain,AIN,ain,ain
replace 
var str = "Visit Microsoft!"; 
var res = str.replace("Microsoft", “Apple"); 
// Visit Apple
Search() 
var str = "Visit Apple!"; 
var n = str.search(“Apple"); 
// 6
slice() 
var str = "Hello world!"; 
var res = str.slice(1,5); 
// ello
split() 
var str = "How are you doing today?"; 
var res = str.split(" "); 
// How,are,you,doing,today? (array)
substr() 
var str = "Hello world!"; 
var res = str.substr(1, 4) 
//ello 
// desde el 1º 4 caracteres
substring() 
var str = "Hello world!"; 
var res = str.substring(1, 4); 
// ell 
// desde el 1º al 4º caracter sin incluirlo.
toLowerCase() 
var str = "Hello World!"; 
var res = str.toLowerCase(); 
// hello world
toUpperCase() 
var str = "Hello World!"; 
var res = str.toUpperCase(); 
// HELLO WORLD
trim() 
var str = " Hello World! "; 
alert(str.trim()); 
//Hello World
valueOf 
var str = “1234"; 
var res = str.valueOf(); 
// 1234
anchor() 
var txt = "Chapter 10"; 
txt.anchor("chap10"); 
// <a name="chap10">Chapter 10</a>
big() 
var str = "Hello World!"; 
var result = str.big(); 
// Hello World!
Y más… 
var txt = "Hello World!"; 
document.write("The original string: " + txt); 
document.write("<p>Big: " + txt.big() + "</p>"); 
document.write("<p>Small: " + txt.small() + "</p>"); 
document.write("<p>Bold: " + txt.bold() + "</p>"); 
document.write("<p>Italic: " + txt.italics() + "</p>"); 
document.write("<p>Fixed: " + txt.fixed() + "</p>"); 
document.write("<p>Strike: " + txt.strike() + "</p>"); 
document.write("<p>Fontcolor: " + txt.fontcolor("green") + "</p>"); 
document.write("<p>Fontsize: " + txt.fontsize(6) + "</p>"); 
document.write("<p>Subscript: " + txt.sub() + "</p>"); 
document.write("<p>Superscript: " + txt.sup() + "</p>"); 
document.write("<p>Link: " + txt.link("http://www.itmaster.com.ar") + 
"</p>");

Javascript strings

  • 1.
  • 2.
    charAt() var str= "HELLO WORLD"; var res = str.charAt(0); // H
  • 3.
    charCodeAt() var str= "HELLO WORLD"; var n = str.charCodeAt(0); /72
  • 4.
    concat() var str1= "Hello "; var str2 = "world!"; var res = str1.concat(str2); // Hello world
  • 5.
    fromCharCode() var res= String.fromCharCode(65); // A
  • 6.
    indexOf() var str= "Hello world, welcome to the universe."; var n = str.indexOf("welcome"); // 13
  • 7.
    lastIndexOf() var str= "Hello planet earth, you are a great planet."; var n = str.lastIndexOf("planet"); // 36
  • 8.
    match() var str= "The rain in SPAIN stays mainly in the plain"; var res0 = str.match(/ain/g); //global var res1 = str.match(/ain/gi); //global ignore case // ain,ain,ain // ain,AIN,ain,ain
  • 9.
    replace var str= "Visit Microsoft!"; var res = str.replace("Microsoft", “Apple"); // Visit Apple
  • 10.
    Search() var str= "Visit Apple!"; var n = str.search(“Apple"); // 6
  • 11.
    slice() var str= "Hello world!"; var res = str.slice(1,5); // ello
  • 12.
    split() var str= "How are you doing today?"; var res = str.split(" "); // How,are,you,doing,today? (array)
  • 13.
    substr() var str= "Hello world!"; var res = str.substr(1, 4) //ello // desde el 1º 4 caracteres
  • 14.
    substring() var str= "Hello world!"; var res = str.substring(1, 4); // ell // desde el 1º al 4º caracter sin incluirlo.
  • 15.
    toLowerCase() var str= "Hello World!"; var res = str.toLowerCase(); // hello world
  • 16.
    toUpperCase() var str= "Hello World!"; var res = str.toUpperCase(); // HELLO WORLD
  • 17.
    trim() var str= " Hello World! "; alert(str.trim()); //Hello World
  • 18.
    valueOf var str= “1234"; var res = str.valueOf(); // 1234
  • 19.
    anchor() var txt= "Chapter 10"; txt.anchor("chap10"); // <a name="chap10">Chapter 10</a>
  • 20.
    big() var str= "Hello World!"; var result = str.big(); // Hello World!
  • 21.
    Y más… vartxt = "Hello World!"; document.write("The original string: " + txt); document.write("<p>Big: " + txt.big() + "</p>"); document.write("<p>Small: " + txt.small() + "</p>"); document.write("<p>Bold: " + txt.bold() + "</p>"); document.write("<p>Italic: " + txt.italics() + "</p>"); document.write("<p>Fixed: " + txt.fixed() + "</p>"); document.write("<p>Strike: " + txt.strike() + "</p>"); document.write("<p>Fontcolor: " + txt.fontcolor("green") + "</p>"); document.write("<p>Fontsize: " + txt.fontsize(6) + "</p>"); document.write("<p>Subscript: " + txt.sub() + "</p>"); document.write("<p>Superscript: " + txt.sup() + "</p>"); document.write("<p>Link: " + txt.link("http://www.itmaster.com.ar") + "</p>");