String Object Method In TypeScript: Part 7

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
  1. string.toUpperCase()  
Function
  1. toUpperCase() {  
  2.  var str = prompt("Please Enter String In Lower Case");  
  3.  var upperstr = str.toUpperCase();  
  4.  var span = document.createElement("span");  
  5.  span.style.color = "blue";  
  6.  span.innerText = "toUpperCase Method \n String is-> " + str + "\n Converted In Upper Case string is-> " + upperstr + "\n";  
  7.  document.body.appendChild(span);  
  8. }  
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
  1. class toUpperCase {  
  2.  toUpperCase() {  
  3.   var str = prompt("Please Enter String In Lower Case");  
  4.   var upperstr = str.toUpperCase();  
  5.   var span = document.createElement("span");  
  6.   span.style.color = "blue";  
  7.   span.innerText = "toUpperCase Method \n String is-> " + str + "\n Converted In Upper Case string is-> " + upperstr + "\n";  
  8.   document.body.appendChild(span);  
  9.  }  
  10. }  
  11. window.onload = () => {  
  12.  var obj = new toUpperCase();  
  13.  obj.toUpperCase();  
  14. };  
toUpperCase_MethodDemo.htm
  1. <!DOCTYPE html>  
  2. <html lang="en"  
  3.     xmlns="http://www.w3.org/1999/xhtml">  
  4.     <head>  
  5.         <meta charset="utf-8" />  
  6.         <title>TypeScript HTML App</title>  
  7.         <link rel="stylesheet" href="app.css" type="text/css" />  
  8.         <script src="toUpperCase.js"></script>  
  9.     </head>  
  10.     <body>  
  11.         <h3>toUpperCase() String Object Method In TypeScript</h3>  
  12.         <div id="content"/>  
  13.     </body>  
  14. </html>  
toUpperCase.js
  1. var toUpperCase = (function() {  
  2.  function toUpperCase() {}  
  3.  toUpperCase.prototype.toUpperCase = function() {  
  4.   var str = prompt("Please Enter String In Lower Case");  
  5.   var upperstr = str.toUpperCase();  
  6.   var span = document.createElement("span");  
  7.   span.style.color = "blue";  
  8.   span.innerText = "toUpperCase Method \n String is-> " + str + "\n Converted In Upper Case string is-> " + upperstr + "\n";  
  9.   document.body.appendChild(span);  
  10.  };  
  11.  return toUpperCase;  
  12. })();  
  13. window.onload = function() {  
  14.  var obj = new toUpperCase();  
  15.  obj.toUpperCase();  
  16. };  
Output 1
 
Enter the string in lowercase and click on "Ok."
 
 enter-string-in-lower-case.jpg
 
Output 2
 
 Upper-case-string.jpg


Similar Articles