-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06.string_operations.js
More file actions
135 lines (53 loc) · 2.1 KB
/
06.string_operations.js
File metadata and controls
135 lines (53 loc) · 2.1 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// // Example 52 : Searching substring in strings - String.prototype.indexOf()
// let message = 'I love javascript and node.js, but I also worked with PHP';
//
// console.log(message.indexOf('javascript')); // start index if found
// console.log(message.indexOf('ruby')); // -1 for not found
// // Example 53: String.prototype.substring(startIndex, endIndex);
// let anyString = 'Mozilla';
//
// // start at index 0 and go upto(not including) index 3
// console.log(anyString.substring(0, 3));
//
// // go back to index 0 from 3(not including 3)
// console.log(anyString.substring(3, 0));
//
// // get everything after index
// console.log(anyString.substring(3));
// // // Example 54: String.prototype.substr(startIndex, length);
// let anyString = 'Mozilla';
//
// // start at index 0 and go upto(not including) index 3
// console.log(anyString.substr(0, 3));
//
// // get last 2 characters
// console.log(anyString.substr(-2, 2));
//
// // get last 2 characters leaving 1 after it
// console.log(anyString.substr(-3, 2));
// // Example 55 : finding the full word from a portion of it - String.prototype.indexOf()
// let message = 'I love javascript and node.js, but I also worked with PHP';
//
// let wordStart = message.indexOf('java');
// let wordEnd = message.indexOf(' ', wordStart);
//
// console.log(message.substring(wordStart, wordEnd));
//
//
//
// wordStart = message.indexOf('no');
// wordEnd = message.indexOf(' ', wordStart);
//
// console.log(message.substring(wordStart, wordEnd));
// // Example 56: length of string
// let message = 'I love javascript and node.js, but I also worked with PHP';
// console.log(message.length);
// // Example 57: Splitting string : String.prototype.split(seperator, limit)
// let message = 'I love javascript and node.js, but I also worked with PHP';
// console.log(message.split(' '));
//
// console.log(message.split(/[ ,]/)); // with regex
// Example 58: Splitting string : String.prototype.split(seperator, limit)
let message = 'a b c d e f';
console.log(message.split(' '));
console.log(message.split(' ', 3));