|
| 1 | +/* |
| 2 | +THE STRING=> |
| 3 | + In JavaScript, a string is a sequence of zero or more characters.A string literal begins and ends with either a single quote(') or a double quote ("). |
| 4 | +
|
| 5 | + JavaScript strings are primitive values.Also, strings are immutable.It means that if you modify a string, you will always get a new string.The original string doesn’t change. |
| 6 | +
|
| 7 | + A string that begins with a double quote must end with a double quote.Likewise, a string that begins with a single quote must also end with a single quote: |
| 8 | +
|
| 9 | +let greeting = 'Hi'; |
| 10 | +let message = "Bye"; |
| 11 | +
|
| 12 | + The template literals allow you to use the single quotes and double quotes inside a string without the need of escaping them.For example: |
| 13 | +
|
| 14 | + let mesage = `"I'm good". She said"`; |
| 15 | + console.log(mesage); |
| 16 | +
|
| 17 | + //to find length of string |
| 18 | + let str = 'aamir'; |
| 19 | + console.log(str.length); |
| 20 | +
|
| 21 | + //to fetch perticular charecter from string |
| 22 | + console.log(str[2]); |
| 23 | +
|
| 24 | + //to use double qoute in string |
| 25 | + let str1 = "aamir ali \"cse\"\ "; |
| 26 | + console.log(str1); |
| 27 | +
|
| 28 | + //to add two string concate() function used |
| 29 | + let str3 = str.concat(str1); |
| 30 | + console.log(str3); |
| 31 | +
|
| 32 | + //getting sub string from string |
| 33 | + let substr = str1.substr(2, 4); |
| 34 | + let substr2 = str1.substring(2, 4); |
| 35 | + console.log(substr); |
| 36 | + console.log(substr2); |
| 37 | +
|
| 38 | + //to find index of perticular su string in string we use indexof fuction |
| 39 | + let str4 = " this is javascript tutorial"; |
| 40 | + let pos = str4.indexOf('is'); |
| 41 | + console.log(pos); |
| 42 | +
|
| 43 | + //removing white spaces trim() /trimStart()/trimEnd() function used |
| 44 | + console.log(str4); |
| 45 | + console.log(str4.trim()); |
| 46 | +
|
| 47 | + //convert into upper case use toUpperCase() |
| 48 | + console.log(str4.toUpperCase()); |
| 49 | +
|
| 50 | + //to replace string replace() |
| 51 | + console.log(str4.replace('this', 'that')); |
| 52 | +
|
| 53 | +*/ |
| 54 | + |
| 55 | + |
| 56 | + |
0 commit comments