String Methods Part - II tutorial in JavaScript

 <!DOCTYPE html>

<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>String Methods JavaScript</title>
    <script>
        var str = "JavaScript is a GREAT and GREAT Language and it is widely used Language";
        var a = str.charAt(4);
        var a2 = str.charAt(200);
        document.write(a + "<br>");
        document.write(a2 + "<br>");

        var a3 = str.charCodeAt(1); //Gives the character code of "a" in "JavaScript" in output
        var a4 = str.charCodeAt(2); //Gives the character code of "v" in "JavaScript" in output
        document.write(a3 + "<br>");
        document.write(a4 + "<br><br>");

        var a5 = String.fromCharCode(2);
        var a6 = String.fromCharCode(5);
        var a7 = String.fromCharCode(65);
        var a8 = String.fromCharCode(90);
        var a9 = String.fromCharCode(110);
        document.write(a5 + "<br>");
        document.write(a6 + "<br>");
        document.write(a7 + "<br>");
        document.write(a8 + "<br>");
        document.write(a9 + "<br><br>");

        var strTwo = ", Hello";
        var strThree = ", How are you ?";
        var a10 = str.concat(strTwo);
        document.write(a10 + "<br>");
        var a11 = str.concat(strTwo, strThree);
        document.write(a11 + "<br><br>");

        var a12 = str.split(" ");   //split() function will give a Array after spliting a whole String
        //split() function will split whole string after given terms in split() function(Above given terms is " " space)
        document.write(a12 + "<br><br>");
        var a13 = str.split("i");
        document.write(a13 + "<br><br>");

        var a14 = str.repeat(2);
        document.write(a14 + "<br><br>");
        var a15 = str.repeat(5);
        document.write(a15 + "<br><br>");

        var a16 = str.slice(3); //slice() function is used to take any word from given whole string
        document.write(a16 + "<br><br>");
        var a17 = str.slice(3, 10);
        document.write(a17 + "<br><br>");
        var a18 = str.slice(-1);
        document.write(a18 + "<br>");
        var a19 = str.slice(-2);
        document.write(a19 + "<br>");

        var a20 = str.substr(2);
        document.write(a20 + "<br>");
        var a21 = str.substr(2, 5);
        document.write(a21 + "<br>");
        var a22 = str.substring(3, 5);
        document.write(a22 + "<br>");
        var a23 = str.substring(3, 7);
        document.write(a23 + "<br><br>");

        var strTwo = 50;
        var a24 = strTwo.toString();
        document.write(a24 + "<br>");
        document.write(a24 + 30 + "<br>");

        var a25 = str.valueOf();
        document.write(a25);

    </script>
</head>

<body>
</body>

</html>



Comments

Popular posts from this blog

Symbols tutorial in Advance JavaScript

Async and Await Method tutorial in Advance JavaScript

String Methods in JavaScript