Topic 7: String, its property and methods - 1 to 7

//Revision Lecture 9: 4 Oct 2022

//Topic 7: //* String: property and methods - 1 to 7 *//


// string: any character or symbol or number written in single or double quotes

let p = 'Sachin Tendulkar'
let p1 = "Virendra Sehwag"
let p2 = "123456"
let p3 = "@"
let p4 = "MH04@15"

let p5 = "Ram" + 10
console.log(p5)
//output---> Ram10

let p6 = "Ram" + 10 + 5
console.log(p6)
//output---> Ram105

let p7 = 10 + 5 + "Ram"
console.log(p7)
//output---> 15Ram


//A) String property

//1) length : returns the length of string

let h1 = 'Shriram'
console.log(h1.length)
//output---> 7

let h2 = 'sachin ramesh tendulkar'
console.log(h2.length)
//output---> 23

//----------------------

//B) String methods:

// 1)  charAt() : method returns the character at a specified index (position) in a string

let h3 = "Suhas"
console.log(h3.charAt(0))
//output---> S

console.log(h3.charAt(2))
//output---> h


// 2)  startsWith() : Checks whether a string begins with specified characters and returns boolean value

let h4 = "tuljapur"
console.log(h4.startsWith('t'))
//output---> true

console.log(h4.startsWith('u'))
//output---> false

console.log(h4.startsWith('tul'))
//output---> true


// 3)  endsWith() : Checks whether a string ends with specified characters and returns boolean value

let h5 = 'dharashiv'
console.log(h5.endsWith('v'))
//output---> true

console.log(h5.endsWith('i'))
//output---> false

console.log(h5.endsWith('shiv'))
//output---> true


// 4)  includes() : Returns boolean value if a string contains a specified value

let h6 = 'Mumbai'
console.log(h6.includes('M'))
//output---> true

console.log(h6.includes('u'))
//output---> true

console.log(h6.includes('j'))
//output---> false


// 5)  indexOf() : Returns the index (position) of the first occurrence of a value in a string

let h7 = "Kolhapur"
console.log(h7.indexOf('K'))
//output---> 0

console.log(h7.indexOf('a'))
//output---> 4

let h8 = 'Pralhad'
console.log(h8.indexOf('a'))
//output---> 2


// 6)  repeat() : returns a new string with a number of copies of a string

let h9 = 'Ramesh'
console.log(h9.repeat(3))
//output---> RameshRameshRamesh


// 7)  concat() : joins two different strings

let h10 = "Rahul"
let h11 = "Dravid"
console.log(h10.concat(h11))
//output---> RahulDravid

console.log(h11.concat(h10))
//output---> DravidRahul

//---------------------------

टिप्पण्या