String Object Method In TypeScript: Part 7
Before reading this article, please go through the following articles:
-
-
-
-
-
-
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
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();
- };
Output 1
Enter the string in lowercase and click on "Ok."
Output 2