-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringInJS.js
More file actions
49 lines (33 loc) · 1.64 KB
/
stringInJS.js
File metadata and controls
49 lines (33 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* Created by thangnv on 5/20/15.
*/
require ("./stringMethodExtend.js");
var str = "This is the test Text in javascript , using javascript methods";
//indexOf method
console.log(str.indexOf("javascript"));
//find the index of keyword in string appear from 0
//lastIndexOf method
console.log(str.lastIndexOf("javascript")); //find the index of keyword in string appear from the end
//Search method
console.log(str.search("javascript")); //the same indexOf method
//slice method
console.log(str.slice(str.indexOf("javascript"),str.indexOf("javascript")+10)); //cut string from ... to ... index of char
console.log(str.slice(str.indexOf("javascript")));//cut string from ... index of char
console.log("Slice Method : "+str.slice(-18,-8));//using negative is not work with < IE 8
//substring method
console.log("Substring method : "+str.substring(44,54));
//substr method
console.log("Substr method : "+str.substr(25,10));
//replace method
console.log("replace method : "+str.replace(/javascript/g,"node.js"));
//upperCase and lowerCase
console.log("upperCase and lowerCase method : "+str.toUpperCase()+" -- "+str.toLowerCase());
//toLocateUpperCase and toLocateLowerCase
//console.log("toLocateUpperCase and toLocateLowerCase : "+str.toLocaleUpperCase()+" -- "+str.toLocaleLowerCase());
//concat
console.log("Concat method : "+str.concat(" **Add new string to**","this is second string (optional)"));
//charAt and charCodeAt
console.log("CharAt and CharCodeAt : "+str.charAt(44)+" -- "+str.charCodeAt(44)); //unsafe because not work with IE 5,6,7
//split
console.log("split method : "+ "hallo".split(""));
console.log("test camel function ".camelUpperCase());