String Object Method In TypeScript: Part 6

Before reading this article, please go through the following articles:

  1. String Object Method In TypeScript: Part 1

  2. String Object Method In TypeScript: Part 2

  3. String Object Method In TypeScript: Part 3

  4. String Object Method In TypeScript: Part 4

  5. String Object Method In TypeScript: Part 5

 

Introduction

The String object is used to manage a series of characters. A String object contains the complete information about a string. In TypeScript, the String objects are created with "new String()".

In this article I am describing the string object's "toLowerCase" method in the TypeScript.

toLoweCase() Method

 

In TypeScript, the toLowerCase() method returns a new string with all uppercase letters converted to lowercase. These methods have no parameters, but don't forget to include the empty set of parentheses after the method name.

Syntax

string.toLowerCase()

Function

toLowerCase()

    {

        var str = prompt("Please Enter String In Upper Case");

        var lowerstr = str.toLowerCase();

        var span = document.createElement("span");

        span.style.color = "green";

        span.innerText = "toLowerCase Method \n String is-> " + str + "\n Converted In Lower Case string is-> " + lowerstr + "\n";

        document.body.appendChild(span);

    }

 

The following example shows how to use the toLowerCase method in TypeScript. In this example, we get the uppercase string from the user and this method returns a new string with all uppercase letters converted to lowercase.

 

Complete Program

toLowerCase.ts

class toLowerCase

{

    toLowerCase()

    {

        var str = prompt("Please Enter String In Upper Case");

        var lowerstr = str.toLowerCase();

        var span = document.createElement("span");

        span.style.color = "green";

        span.innerText = "toLowerCase Method \n String is-> " + str + "\n Converted In Lower Case string is-> " + lowerstr + "\n";

        document.body.appendChild(span);

    }

}

window.onload = () =>

{

    var obj = new toLowerCase();

    obj.toLowerCase();

};

 

toLowerCase_MethodDemo.htm

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">

<head>

    <meta charset="utf-8" />

    <title>TypeScript HTML App</title>

    <link rel="stylesheet" href="app.css" type="text/css" />

    <script src="toLowerCase.js"></script>

</head>

<body>

    <h3>toLowerCase() String Object Method In TypeScript</h3>

    <div id="content"/>

</body>

</html>

 

toLowerCase.js

var toLowerCase = (function () {

    function toLowerCase() { }

    toLowerCase.prototype.toLowerCase = function () {

        var str = prompt("Please Enter String In Upper Case");

        var lowerstr = str.toLowerCase();

        var span = document.createElement("span");

        span.style.color = "green";

        span.innerText = "toLowerCase Method \n String is-> " + str + "\n Converted In Lower Case string is-> " + lowerstr + "\n";

        document.body.appendChild(span);

    };

    return toLowerCase;

})();

window.onload = function () {

    var obj = new toLowerCase();

    obj.toLowerCase();

};

//@ sourceMappingURL=toLowerCase.js.map
 

Output 1

Enter a string in uppercase and click on "Ok".


 Enter-String.jpg


Output 2


 lower-case-string.jpg

Up Next
    Ebook Download
    View all

    Test

    Read by 16 people
    Download Now!
    Learn
    View all