0% found this document useful (0 votes)
185 views7 pages

Javascript String Methods

The document discusses JavaScript string methods. It provides a list of common string properties like length and constructor. It also lists 18 common string methods such as charAt(), indexOf(), concat(), toUpperCase(), and split(). The document includes a program that implements many of these string methods like charAt(), charCodeAt(), concat(), indexOf(), lastIndexOf(), toUpperCase(), toLowerCase(), substr(), split(), and slice(). The output of running the program is displayed.

Uploaded by

Rohit Gadekar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
185 views7 pages

Javascript String Methods

The document discusses JavaScript string methods. It provides a list of common string properties like length and constructor. It also lists 18 common string methods such as charAt(), indexOf(), concat(), toUpperCase(), and split(). The document includes a program that implements many of these string methods like charAt(), charCodeAt(), concat(), indexOf(), lastIndexOf(), toUpperCase(), toLowerCase(), substr(), split(), and slice(). The output of running the program is displayed.

Uploaded by

Rohit Gadekar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

COMPUTER ENGINEERING DEPARTMENT

Subject :C lIent Side Scripting Subject Code: 22519


Semester: 5th Course: Computer Engineering
Laboratory No: L001B Name of Subject Teacher: Kshrisagar S.B.
Name of Student: Nitin Santosh Jori Roll Id: 31

Experiment No: 5
Title of Experiment Developed JavaScript to implement string.

Theory:

JavaScript String Methods
String Methods and Properties
The String object lets you work with a series of characters; it wraps Javascript's
string primitive data type with a number of helper methods.
As JavaScript automatically converts between string primitives and String objects,
you can call any of the helper methods of the String object on a string primitive.

Syntax
Use the following syntax to create a String object −
varval = new String(string);
The String parameter is a series of characters that has been properly encoded.

String Properties
Sr.No Property & Description
.

1 constructor

Returns a reference to the String function that created the object.

Page | 1
2 length

Returns the length of the string.

3 prototype

The prototype property allows you to add properties and methods to an object.

Here is a list of the properties of String object and their description.


In the following sections, we will have a few examples to demonstrate the usage of
String properties.

String Methods
Here is a list of the methods available in String object along with their description.

Sr.No Method & Description


.

1 charAt()

Returns the character at the specified index.

2 charCodeAt()

Returns a number indicating the Unicode value of the character at the given index.

3 concat()

Combines the text of two strings and returns a new string.

4 indexOf()

Returns the index within the calling String object of the first occurrence of the specified value,
or -1 if not found.

5 lastIndexOf()

Returns the index within the calling String object of the last occurrence of the specified value,
or -1 if not found.

6 localeCompare()

Returns a number indicating whether a reference string comes before or after or is the same
as the given string in sort order.

7 match()

Page | 2
Used to match a regular expression against a string.

8 replace()

Used to find a match between a regular expression and a string, and to replace the matched
substring with a new substring.

9 search()

Executes the search for a match between a regular expression and a specified string.

10 slice()

Extracts a section of a string and returns a new string.

11 split()

Splits a String object into an array of strings by separating the string into substrings.

12 substr()

Returns the characters in a string beginning at the specified location through the specified
number of characters.

13 substring()

Returns the characters in a string between two indexes into the string.

14 toLocaleLowerCase()

The characters within a string are converted to lower case while respecting the current locale.

15 toLocaleUpperCase()

The characters within a string are converted to upper case while respecting the current locale.

16 toLowerCase()

Returns the calling string value converted to lower case.

17 toString()

Returns a string representing the specified object.

18 toUpperCase()

Returns the calling string value converted to uppercase.

Page | 3
19 valueOf()

Returns the primitive value of the specified object.

Program:

<!DOCTYPE html>

<html>

<head>

<title>String|Method().</title>

</head>

<body>

<center>

<script type="text/javascript">

var str = new String("This is String 1")

document.write(str1);

document.write("<br/>");

document.write("<br/>");

var str1 = new String("This is String 2")

document.write(str1);

document.write("<br/>");

document.write("<br/>");

document.writeln("str.charAt(1) is:- " + str.charAt(1));

document.write("<br/>");

document.write("<br/>");

document.writeln("str1.charCodeAt(3) is:- " + str.charCodeAt(3));

document.write("<br/>");

document.write("<br/>");

Page | 4
var str2 = str.concat(str1);

document.writeln("concatenated String is:- " + str2);

document.write("<br/>");

document.write("<br/>");

var index = str1.indexOf("String");

document.writeln("indexOf found String:- " + index);

document.write("<br/>");

document.write("<br/>");

var index1 = str.lastIndexOf("1");

document.writeln("lastIndexOf found String:- " + index1);

document.write("<br/>");

document.write("<br/>");

document.writeln(str1.valueOf());

document.write("<br/>");

document.write("<br/>");

document.writeln(str.toUpperCase());

document.write("<br/>");

document.write("<br/>");

document.writeln(str1.toString());

document.write("<br/>");

document.write("<br/>");

document.writeln(str.toLocaleUpperCase());

document.write("<br/>");

document.write("<br/>");

document.writeln(str1.toLowerCase());

document.write("<br/>");

Page | 5
document.write("<br/>");

document.writeln(str.toLocaleLowerCase());

document.write("<br/>");

document.write("<br/>");

document.writeln("(1,2):" + str.substr(1,2));

document.write("<br/>");

document.write("<br/>");

var splitted=str.split("",3);

document.writeln(splitted);

document.write("<br/>");

document.write("<br/>");

var sliced=str1.slice(3,-2);

document.writeln(sliced);

</script>

</center>

</body>

</html>

Page | 6
Output:

Grade and C (35 M) P (15 M) Total ( 50 M) Dated Sign


Dated
Signature of
Teacher

Page | 7

You might also like