Topic 7: String: property and methods - 8 to 14

//Revision Lecture 10: 6 Oct 2022

//Topic 7: //* String: property and methods - 8 to 14 *//


// 8)  slice(): extracts a part of a string and returns the extracted part in a new string.

//              01234567   
let h12 = 'Sinhagad'
console.log(h12.slice(0,5))

//              0123456789101112
let h13 = "mango, banana"
console.log(h13.slice(8,12))


// 9)  replace(): method replaces a specified value with another value in a string

let h14 = 'Ramesh'
console.log(h14.replace('Ra','U'))

let m1 = 'Tuljai'
console.log(m1.replace('T','A'))

let h15 = 'Virendra Sehwag'
console.log(h15.replace('Virendra','Ram'))


// 10) toUpperCase(): A string is converted to upper case

let h16 = 'yuvraj singh'
console.log(h16.toUpperCase())

let h17 = 'virat kohli'
console.log(h17.toUpperCase())

// 11) toLowerCase(): A string is converted to upper lowercase

let h18 = 'ROHIT SHARMA'
console.log(h18.toLocaleLowerCase())

let h19 = 'UMESH YADAV'
console.log(h19.toLowerCase())


// 12) trim(): removes whitespace from both sides of a string

let h20 = ' Hello '
console.log(h20)
console.log(h20.trim())

let h21 = ' Welcome '
console.log(h21)
console.log(h21.trim())


// 13) trimStart(): removes whitespace only from the start of a string

let h22 = ' Hanuman'
console.log(h22)
console.log(h22.trimStart())

let h23 = ' Sita'
console.log(h23)
console.log(h23.trimStart())


// 14) trimEnd(): removes whitespace only from the end of a string

let h24 = 'Laxman '
console.log(h24.trimEnd())

let h25 = 'Ram '
console.log(h25.trimEnd())

टिप्पण्या