String Object Method In TypeScript: Part 7

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

  6. String Object Method In TypeScript: Part 6

 

Introduction

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

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

toUpperCase() Method

 

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

Syntax

string.toUpperCase()

Function

toUpperCase()

    {

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

        var upperstr = str.toUpperCase();

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

        span.style.color = "blue";

        span.innerText = "toUpperCase Method \n String is-> " + str + "\n Converted In Upper Case string is-> " + upperstr + "\n";

        document.body.appendChild(span);

    }

 

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

 

Complete Program

toUpperCase.ts

class toUpperCase

{

    toUpperCase()

    {

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

        var upperstr = str.toUpperCase();

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

        span.style.color = "blue";

        span.innerText = "toUpperCase Method \n String is-> " + str + "\n Converted In Upper Case string is-> " + upperstr + "\n";

        document.body.appendChild(span);

    }

}

window.onload = () =>

{

    var obj = new toUpperCase();

    obj.toUpperCase();

};

 

toUpperCase_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="toUpperCase.js"></script>

</head>

<body>

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

    <div id="content"/>

</body>

</html>

 

toUpperCase.js

var toUpperCase = (function () {

    function toUpperCase() { }

    toUpperCase.prototype.toUpperCase = function () {

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

        var upperstr = str.toUpperCase();

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

        span.style.color = "blue";

        span.innerText = "toUpperCase Method \n String is-> " + str + "\n Converted In Upper Case string is-> " + upperstr + "\n";

        document.body.appendChild(span);

    };

    return toUpperCase;

})();

window.onload = function () {

    var obj = new toUpperCase();

    obj.toUpperCase();

};

//@ sourceMappingURL=toUpperCase.js.map
 

Output 1

Enter the string in lowercase and click on "Ok".


 enter-string-in-lower-case.jpg


Output 2


 Upper-case-string.jpg

Up Next
    Ebook Download
    View all

    Test

    Read by 16 people
    Download Now!
    Learn
    View all