-
Notifications
You must be signed in to change notification settings - Fork 0
/
Strings.js
88 lines (42 loc) · 1.84 KB
/
Strings.js
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
let nam = "John Doe"
let b = 'Abhinav mishra' //single & double quotes both are allowed
console.log(nam.concat(" ", b))
let ano = "this string contain's afostofi s"
let esp = "this is the \"Escape\" Character"
console.log(esp)
console.log(nam+ ' \v ' + b + '\n& ' + ano+ '\t= '+ ano.length)
let lb = "line break is \
here"
console.log(lb)
// String variable created with new keyword is a object of string
let ob = 'joshua'
let str_obj = new String('joshua')
console.log(ob.toUpperCase())
console.log(ob==str_obj?"equal":"not equal") //'==' comapres with only values
console.log(ob===str_obj?"equal":"not equal") //'===' compares with values & data-types too
console.log('index of u ' + ob.indexOf('u'))
// string slicing
let str = "I m future front end Developer"
console.log(str.charAt(21))
console.log(str.slice(21)) //slicing 'Developer' from whole string
console.log(str.split(" ")) // converting string to Array ******
// string replacing
let str2 = 'JavaScript Expert'
str2 = str2.replace('JavaScript', 'JS')
console.log(str2)
// str2 = str2.replace('Java', 'JS')
// console.log(str2)
let tr = " hello world developer "
console.log(tr.trim()) //trims white spaces from both side
console.log(tr.includes('developer')) // returns true if string have the character/ string
let pd = 'h'
console.log(pd.padStart(5,'i')) //padStart creates n-1 times of character before string
console.log(pd.padEnd(5,'x'))
// String Template
let j = "kayach"
let f2 = "dibakar"
console.log(`${j} and ${f2} are very good friends`) // String Interpolation
let sentence = "hello world developer"
let word = 'Developer'
console.log(`The word "${word}" ${sentence.includes(word)?'is':'is not'} in the Sentence`)
console.log(' sentence is starts with he: ' + sentence.startsWith('he')+ ' & ends With ee: ' + sentence.endsWith('ee'))