Breaking News
yeni film izle hd film seyret film izle

String Objects In JavaScript

A string is a group of Characters .
M -> is a Character
Moral -> is a group of Characters or contains 5
Characters or is a string.
 
A string is an Object
A string is an object in Javascript , an object have properties and methods or functions, so a string is having property and methods in javascript.
 
String property
Length – property returns the no of characters present in string.
 
String Methods
bold() – returns the string formatting to bold.
italics() – returns the string formatting italics.
charAt() – returns the character present in string at given position.
substring() – returns the characters present from given start position to given end position.
toLowerCase() – returns the string converted to lowercase letters.
toUpperCase() – returns the string converted to uppercase letters.
 
Length
 
Length  is a property of sring object, using which we can know the number of characters in a string.
 
Example 1:
 
<html>

            <head>

            <script>

                        var a=”Hindustan”

                        document.write(“Length of Variable a is “+a.length);

            </script>

            </html>

 
Output will be:
Length of Variable a is 9
 
 
Example 2:
 
<html>

            <head>

            <script>

                        var name=”Manmohan Singh”

                        document.write(“Length of Variable a is “+name.length);

            </script>

            </html>

 
 
Output will be:
Length of Variable a is 14
 
String Methods –  bold()
 
Example 1:
 
<html>

<head>

<script>

            var a=”Uttar Pradesh”

            document.write(“The Value of Variable a is “+a.bold());

</script>

</html>

 
Output will be :
The Value of Variable a is Uttar Pradesh
 
 
Example 2:
 
<html>

<head>

<script>

            var state=”Bihar”

            document.write(“State : “+state.bold());

</script>

</html>

 
Output will be:
State : Bihar
 
 
String Methods – charAt()
 
Example 1:
 
<html>

<head>

<script>

            var state=”Bihar”

            document.write(“<br>character at 0th position is : “+state.charAt(0));

            document.write(“<br>character at 1st position is : “+state.charAt(1));

            document.write(“<br>character at 2nd position is : “+state.charAt(2));

</script>

</html>

 
Output will be :
character at 0th position is : B
character at 1st position is : i
character at 2nd position is : h
 
Exapmple 2:
 
<html>

<head>

<script>

            var state=”Bihar”

            state=state.charAt(2).bold().italics()

            document.write(“Character at 2nd position is  : “+state);

</script>

</html>

 
Output will be:
Character at 2nd position is : h
 
 
String Methods – italics()
 
Example 1:
 
<html>

<head>

<script>

var state=”Bihar”

document.write(“State : “+state.italics());

</script>

</html>

 
Example 2:
 
<html>

<head>

<script>

            var state=”Bihar”

            state=state.bold();

            state=state.italics();

            document.write(“State : “+state);

</script>

</html>

 
 
String Methods – toLowerCase()
 
Example 1:
 
<html>

<head>

<script>

            var state=”HIMANCHAL PRADESH”

            state=state.toLowerCase()

            document.write(“State  : “+state);

</script>

</html>

 
Output will be:
State : himanchal pradesh
 
Example 2:
 
<html>

<head>

<script>

            var state=”HIMANCHAL PRADESH”

            state=state.substring(0,state.length).toLowerCase().bold().italics()

            document.write(“State  : “+state);

</script>

</html>

 
Output will be :
State : himanchal Pradesh
 
 
String Methods – toUpperCase()
 
Example 1:
 
<html>

<head>

<script>

            var state=”uttranchal”

            state=state.toUpperCase()

            document.write(“State  : “+state);

</script>

</html>

 
Example 2:
 
<html>

<head>

<script>

var state=”uttranchal”

state=state.substring(0,state.length).toUpperCase().bold().italics()

document.write(“State  : “+state);

</script>

</html>

 
output will be:
State : UTTRANCHAL
 
 
String Methods – substring()
 
Example 1:
 
<html>

<head>

<script>

            var state=”Bihar”

            state=state.substring(0,3)

            document.write(“Characters from 0th to 2nd position are  : “+state);

</script>

</html>

 
Output will be:
Characters from 0th to 2nd position are : Bih
 
 
Example 2:
 
<html>

<head>

<script>

            var state=”Bihar”

            state=state.substring(0,3).bold().italics()

            document.write(“Characters from 0th to 2nd position are  : “+state);

</script>

</html>

 
Output will be:
Characters from 0th to 2nd position are : Bih
 

Check Also

Functions Returning Values In Java Script

Function is a set of statements recognized by a name and can be used as …