SlideShare a Scribd company logo
Content
• String Functions
Covered String Functions
• charAt()
• concat()
• indexOf()
• lastIndexOf()
• replace()
• search()
• substr()
• substring()
• toLowerCase()
• toUppserCase()
charAt()
Description:
• This method returns the character from the
specified index. Characters in a string are indexed
from left to right.
• The index of the first character is 0, and the index
of the last character in a string called string Name
is stringName.length - 1.
Syntax:
string.charAt(index);
charAt
Example
<html>
<head>
<title>JavaScript String charAt() Method</title>
</head>
<body>
<script type="text/JavaScript">
var str = new String( "This is string" );
document.writeln("str.charAt(0) is:" + str.charAt(0));
</script>
</body>
</html>
Output
str.charAt(0) is: T
concat()
Description:
• This method adds two or more strings and returns a new
single string.
Syntax:
string.concat(string2, string3[, ..., stringN]);
parameters:
string2...stringN : These are the strings to be concatenated.
concat()
Example:
<html>
<head>
<title>JavaScript String concat() Method</title>
</head>
<body>
<script type="text/javascript">
var str1 = new String( "This is string one" );
var str2 = new String( "This is string two" );
var str3 = str1.concat( str2 );
document.write("Concatenated String :" + str3);
</script>
</body></html>
Output:
Concatenated String :This is string oneThis is string two.
indexOf
Description:
• the first occurrence of the specified value, starting the
search at This method returns the index within the calling
String object of fromIndex or -1 if the value is not found.
Syntax:
string.indexOf(searchValue[, fromIndex])
Parameters:
searchValue : A string representing the value to search for.
fromIndex : The location within the calling string to start the
search from. It can be any integer between 0 and the length
of the string. The default value is 0.
indexOf
Example:
<html>
<head>
<title>JavaScript String indexOf() Method</title>
</head>
<body>
<script type="text/javascript">
var str1 = new String( "This is string one" );
var index = str1.indexOf( "string" );
document.write("indexOf found String :" + index );
document.write("<br />");
var index = str1.indexOf( "one" );
document.write("indexOf found String :" + index );
</script>
</body></html>
Oputput:
indexOf found String :8
indexOf found String :15
lastIndexOf()
Description:
– This method returns the index within the calling String
object of the last occurrence of the specified value, starting
the search at fromIndex or -1 if the value is not found.
Syntax:
– string.lastIndexOf(searchValue[, fromIndex])
Parameters:
– searchValue : A string representing the value to search for.
– fromIndex : The location within the calling string to start the
search from. It can be any integer between 0 and the length
of the string. The default value is 0.
Return Value:
– . Returns the index of the last found occurrence otherwise -1
if not found
lastIndexOf()
Example:
<html>
<head>
<title>JavaScript String lastIndexOf() Method</title>
</head>
<body>
<script type="text/javascript">
var str1 = new String( "This is string one and again string" );
var index = str1.lastIndexOf( "string" );
document.write("lastIndexOf found String :" + index );
document.write("<br />");
var index = str1.lastIndexOf( "one" );
document.write("lastIndexOf found String :" + index );
</script>
</body>
</html>
Output:
lastIndexOf found String :29
lastIndexOf found String :15
replace()
Description:
This method finds a match between a regular expression
and a string, and replaces the matched substring with a new
substring.
The replacement string can include the following special
replacement patterns:
Syntax:
string.replace(regexp/substr, newSubStr/function[, flags]);
replace()
Parameters:
– regexp : A RegExp object. The match is replaced by the
return value of parameter #2.
– substr : A String that is to be replaced by newSubStr.
– newSubStr : The String that replaces the substring received
from parameter #1.
– function : A function to be invoked to create the new
substring.
– flags : A String containing any combination of the RegExp
flags: g - global match, i - ignore case, m - match over
multiple lines. This parameter is only used if the first
parameter is a string.
Return Value:
– It simply returns a new changed string.
replace()
Example:
Following example shows how to use the global and ignore case flags
which permits replace to replace each occurrence of 'apples' in the string
with 'oranges'.
<html>
<head
<title>JavaScript String replace() Method</title>
</head>
<body>
<script type="text/javascript">
var re = /apples/gi;
var str = "Apples are round, and apples are juicy.";
var newstr = str.replace(re, "oranges");
document.write(newstr );
</script>
</body>
</html>
search()
Description:
– This method Executes the search for a match between a
regular expression and this String object.
Syntax:
– string.search(regexp);
Parameters:
– regexp : A regular expression object. If a non-RegExp object
obj is passed, it is implicitly converted to a RegExp by using
new RegExp(obj)
Return Value:
– If successful, search returns the index of the regular
expression inside the string. Otherwise, it returns -1.
search()
Example:
<html>
<head>
<title>JavaScript String search() Method</title>
</head>
<body>
<script type="text/javascript">
var re = /apples/gi;
var str = "Apples are round, and apples are juicy.";
if ( str.search(re) == -1 ){
document.write("Does not contain Apples" );
}else{
document.write("Contains Apples" );
}
</script>
</body>
</html>
Output:
Contains Apples
substr()
Description:
– This method returns the characters in a string beginning at
the specified location through the specified number of
characters.
Syntax:
– string.substr(start[, length]);
Parameters:
– start : Location at which to begin extracting characters (an
integer between 0 and one less than the length of the string).
– length : The number of characters to extract.
Note: If start is negative, substr uses it as a character index
from the end of the string.
Return Value:
– The substr method returns the new sub string based on
given parameters.
substr()
Example:
<html>
<head><title>JavaScript String substr() Method</title></head><body>
<script type="text/javascript">
var str = "Apples are round, and apples are juicy.";
document.write("(1,2): " + str.substr(1,2));
document.write("<br />(-2,2): " + str.substr(-2,2));
document.write("<br />(1): " + str.substr(1));
document.write("<br />(-20, 2): " + str.substr(-20,2));
document.write("<br />(20, 2): " str.substr(20,2));
</script></body></html>
Output:
(1,2): pp
(-2,2): Ap
(1): pples are round, and apples are juicy.
(-20, 2): Ap
(20, 2): d
substring()
Description:
– This method returns a subset of a String object.
Syntax:
– string.substring(indexA, [indexB])
Parameters:
– indexA : An integer between 0 and one less than the length of
the string.
– indexB : (optional) An integer between 0 and the length of the
string.
Return Value:
– The substring method returns the new sub string based on
given parameters
substring()
Example:
<html>
<head><title>JavaScript String substring()
Method</title></head><body>
<script type=”text/javascript”>
var str = “Apples are round, and apples are juicy.”;
document.write( “(1,2): “ + str.substring(1,2));
document.write( “<br />(0,10):” + str.substring(0, 10));
document.write(“<br />(5): “ + str.substring(5));
</script></body> </html>
Output:
(1,2): p(0,10): Apples are (5): s are round, and apples are juicy.
toLowerCase()
Description:
– This method returns the calling string value
converted to lowercase.
Syntax:
– string.toLocaleLowerCase( )
Return Value:
– Returns the calling string value converted to
lowercase.
toLowerCase()
Example:
<html>
<head>
<title>JavaScript String toLowerCase() Method
</title></head><body>
<script type="text/javascript">
var str = "Apples are round, and Apples are Juicy.";
document.write(str.toLowerCase( ));
</script></body> </html>
Output:
apples are round, and apples are juicy.
toUpperCase()
Description:
– This method returns the calling string value converted to
uppercase.
Syntax:
– string.toUpperCase( )
Return Value:
– Returns a string representing the specified object.
toUpperCase()
Example:
<html>
<head>
<title>JavaScript String toUpperCase() Method</title>
</head>
<body>
<script type="text/javascript">
var str = "Apples are round, and Apples are Juicy.";
document.write(str.toUpperCase( ));
</script>
</body>
</html>
Output:
APPLES ARE ROUND, AND APPLES ARE JUICY.
Javascript built in String Functions

More Related Content

What's hot

Javascript functions
Javascript functionsJavascript functions
Javascript functions
Alaref Abushaala
 
Html forms
Html formsHtml forms
jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
Dominic Arrojado
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
Bui Kiet
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
Sanjeev Kumar
 
Javascript essentials
Javascript essentialsJavascript essentials
Javascript essentials
Bedis ElAchèche
 
JavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScriptJavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScript
Laurence Svekis ✔
 
Datatype in JavaScript
Datatype in JavaScriptDatatype in JavaScript
Datatype in JavaScript
Rajat Saxena
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
WebStackAcademy
 
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - Introduction
WebStackAcademy
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
Mohammed Arif
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and FunctionsJussi Pohjolainen
 
jQuery
jQueryjQuery
HTML Forms
HTML FormsHTML Forms
HTML Forms
Ravinder Kamboj
 
Javascript
JavascriptJavascript
Javascript
Nagarajan
 
Css
CssCss
JavaScript - Chapter 4 - Types and Statements
 JavaScript - Chapter 4 - Types and Statements JavaScript - Chapter 4 - Types and Statements
JavaScript - Chapter 4 - Types and Statements
WebStackAcademy
 
Javascript
JavascriptJavascript
Javascript
mussawir20
 

What's hot (20)

Javascript functions
Javascript functionsJavascript functions
Javascript functions
 
Html forms
Html formsHtml forms
Html forms
 
jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
Js ppt
Js pptJs ppt
Js ppt
 
Javascript essentials
Javascript essentialsJavascript essentials
Javascript essentials
 
JavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScriptJavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScript
 
Datatype in JavaScript
Datatype in JavaScriptDatatype in JavaScript
Datatype in JavaScript
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
 
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - Introduction
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and Functions
 
jQuery
jQueryjQuery
jQuery
 
Dom
DomDom
Dom
 
HTML Forms
HTML FormsHTML Forms
HTML Forms
 
Javascript
JavascriptJavascript
Javascript
 
Css
CssCss
Css
 
JavaScript - Chapter 4 - Types and Statements
 JavaScript - Chapter 4 - Types and Statements JavaScript - Chapter 4 - Types and Statements
JavaScript - Chapter 4 - Types and Statements
 
Javascript
JavascriptJavascript
Javascript
 

Similar to Javascript built in String Functions

Javascripting.pptx
Javascripting.pptxJavascripting.pptx
Javascripting.pptx
Vinod Srivastava
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript Objects
Reem Alattas
 
Object Oriented Programming Using C++: C++ STL Programming.pptx
Object Oriented Programming Using C++: C++ STL Programming.pptxObject Oriented Programming Using C++: C++ STL Programming.pptx
Object Oriented Programming Using C++: C++ STL Programming.pptx
RashidFaridChishti
 
Java script arrays
Java script arraysJava script arrays
Java script arrays
Frayosh Wadia
 
Java script arrays
Java script arraysJava script arrays
Java script arrays
Frayosh Wadia
 
WD programs descriptions.docx
WD programs descriptions.docxWD programs descriptions.docx
WD programs descriptions.docx
anjani pavan kumar
 
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Dhivyaa C.R
 
UNIT IV (4).pptx
UNIT IV (4).pptxUNIT IV (4).pptx
UNIT IV (4).pptx
DrDhivyaaCRAssistant
 
UNIT II (7).pptx
UNIT II (7).pptxUNIT II (7).pptx
UNIT II (7).pptx
DrDhivyaaCRAssistant
 
UNIT II (7).pptx
UNIT II (7).pptxUNIT II (7).pptx
UNIT II (7).pptx
DrDhivyaaCRAssistant
 
String handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering College
String handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering CollegeString handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering College
String handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering College
Dhivyaa C.R
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objectsPhúc Đỗ
 
9781305078444 ppt ch08
9781305078444 ppt ch089781305078444 ppt ch08
9781305078444 ppt ch08
Terry Yoast
 
Unitii string
Unitii stringUnitii string
Unitii string
Sowri Rajan
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
Muthuselvam RS
 
13 Strings and Text Processing
13 Strings and Text Processing13 Strings and Text Processing
13 Strings and Text Processing
Intro C# Book
 
What is new in Java 8
What is new in Java 8What is new in Java 8
What is new in Java 8
Sandeep Kr. Singh
 
Java String Handling
Java String HandlingJava String Handling
Java String Handling
Infoviaan Technologies
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
Sujith Kumar
 

Similar to Javascript built in String Functions (20)

Javascripting.pptx
Javascripting.pptxJavascripting.pptx
Javascripting.pptx
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript Objects
 
Object Oriented Programming Using C++: C++ STL Programming.pptx
Object Oriented Programming Using C++: C++ STL Programming.pptxObject Oriented Programming Using C++: C++ STL Programming.pptx
Object Oriented Programming Using C++: C++ STL Programming.pptx
 
Java script arrays
Java script arraysJava script arrays
Java script arrays
 
Java script arrays
Java script arraysJava script arrays
Java script arrays
 
Strings
StringsStrings
Strings
 
WD programs descriptions.docx
WD programs descriptions.docxWD programs descriptions.docx
WD programs descriptions.docx
 
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
 
UNIT IV (4).pptx
UNIT IV (4).pptxUNIT IV (4).pptx
UNIT IV (4).pptx
 
UNIT II (7).pptx
UNIT II (7).pptxUNIT II (7).pptx
UNIT II (7).pptx
 
UNIT II (7).pptx
UNIT II (7).pptxUNIT II (7).pptx
UNIT II (7).pptx
 
String handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering College
String handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering CollegeString handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering College
String handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering College
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objects
 
9781305078444 ppt ch08
9781305078444 ppt ch089781305078444 ppt ch08
9781305078444 ppt ch08
 
Unitii string
Unitii stringUnitii string
Unitii string
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
 
13 Strings and Text Processing
13 Strings and Text Processing13 Strings and Text Processing
13 Strings and Text Processing
 
What is new in Java 8
What is new in Java 8What is new in Java 8
What is new in Java 8
 
Java String Handling
Java String HandlingJava String Handling
Java String Handling
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 

Recently uploaded

The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 

Recently uploaded (20)

The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 

Javascript built in String Functions

  • 1.
  • 3. Covered String Functions • charAt() • concat() • indexOf() • lastIndexOf() • replace() • search() • substr() • substring() • toLowerCase() • toUppserCase()
  • 4. charAt() Description: • This method returns the character from the specified index. Characters in a string are indexed from left to right. • The index of the first character is 0, and the index of the last character in a string called string Name is stringName.length - 1. Syntax: string.charAt(index);
  • 5. charAt Example <html> <head> <title>JavaScript String charAt() Method</title> </head> <body> <script type="text/JavaScript"> var str = new String( "This is string" ); document.writeln("str.charAt(0) is:" + str.charAt(0)); </script> </body> </html> Output str.charAt(0) is: T
  • 6. concat() Description: • This method adds two or more strings and returns a new single string. Syntax: string.concat(string2, string3[, ..., stringN]); parameters: string2...stringN : These are the strings to be concatenated.
  • 7. concat() Example: <html> <head> <title>JavaScript String concat() Method</title> </head> <body> <script type="text/javascript"> var str1 = new String( "This is string one" ); var str2 = new String( "This is string two" ); var str3 = str1.concat( str2 ); document.write("Concatenated String :" + str3); </script> </body></html> Output: Concatenated String :This is string oneThis is string two.
  • 8. indexOf Description: • the first occurrence of the specified value, starting the search at This method returns the index within the calling String object of fromIndex or -1 if the value is not found. Syntax: string.indexOf(searchValue[, fromIndex]) Parameters: searchValue : A string representing the value to search for. fromIndex : The location within the calling string to start the search from. It can be any integer between 0 and the length of the string. The default value is 0.
  • 9. indexOf Example: <html> <head> <title>JavaScript String indexOf() Method</title> </head> <body> <script type="text/javascript"> var str1 = new String( "This is string one" ); var index = str1.indexOf( "string" ); document.write("indexOf found String :" + index ); document.write("<br />"); var index = str1.indexOf( "one" ); document.write("indexOf found String :" + index ); </script> </body></html> Oputput: indexOf found String :8 indexOf found String :15
  • 10. lastIndexOf() Description: – This method returns the index within the calling String object of the last occurrence of the specified value, starting the search at fromIndex or -1 if the value is not found. Syntax: – string.lastIndexOf(searchValue[, fromIndex]) Parameters: – searchValue : A string representing the value to search for. – fromIndex : The location within the calling string to start the search from. It can be any integer between 0 and the length of the string. The default value is 0. Return Value: – . Returns the index of the last found occurrence otherwise -1 if not found
  • 11. lastIndexOf() Example: <html> <head> <title>JavaScript String lastIndexOf() Method</title> </head> <body> <script type="text/javascript"> var str1 = new String( "This is string one and again string" ); var index = str1.lastIndexOf( "string" ); document.write("lastIndexOf found String :" + index ); document.write("<br />"); var index = str1.lastIndexOf( "one" ); document.write("lastIndexOf found String :" + index ); </script> </body> </html> Output: lastIndexOf found String :29 lastIndexOf found String :15
  • 12. replace() Description: This method finds a match between a regular expression and a string, and replaces the matched substring with a new substring. The replacement string can include the following special replacement patterns: Syntax: string.replace(regexp/substr, newSubStr/function[, flags]);
  • 13. replace() Parameters: – regexp : A RegExp object. The match is replaced by the return value of parameter #2. – substr : A String that is to be replaced by newSubStr. – newSubStr : The String that replaces the substring received from parameter #1. – function : A function to be invoked to create the new substring. – flags : A String containing any combination of the RegExp flags: g - global match, i - ignore case, m - match over multiple lines. This parameter is only used if the first parameter is a string. Return Value: – It simply returns a new changed string.
  • 14. replace() Example: Following example shows how to use the global and ignore case flags which permits replace to replace each occurrence of 'apples' in the string with 'oranges'. <html> <head <title>JavaScript String replace() Method</title> </head> <body> <script type="text/javascript"> var re = /apples/gi; var str = "Apples are round, and apples are juicy."; var newstr = str.replace(re, "oranges"); document.write(newstr ); </script> </body> </html>
  • 15. search() Description: – This method Executes the search for a match between a regular expression and this String object. Syntax: – string.search(regexp); Parameters: – regexp : A regular expression object. If a non-RegExp object obj is passed, it is implicitly converted to a RegExp by using new RegExp(obj) Return Value: – If successful, search returns the index of the regular expression inside the string. Otherwise, it returns -1.
  • 16. search() Example: <html> <head> <title>JavaScript String search() Method</title> </head> <body> <script type="text/javascript"> var re = /apples/gi; var str = "Apples are round, and apples are juicy."; if ( str.search(re) == -1 ){ document.write("Does not contain Apples" ); }else{ document.write("Contains Apples" ); } </script> </body> </html> Output: Contains Apples
  • 17. substr() Description: – This method returns the characters in a string beginning at the specified location through the specified number of characters. Syntax: – string.substr(start[, length]); Parameters: – start : Location at which to begin extracting characters (an integer between 0 and one less than the length of the string). – length : The number of characters to extract. Note: If start is negative, substr uses it as a character index from the end of the string. Return Value: – The substr method returns the new sub string based on given parameters.
  • 18. substr() Example: <html> <head><title>JavaScript String substr() Method</title></head><body> <script type="text/javascript"> var str = "Apples are round, and apples are juicy."; document.write("(1,2): " + str.substr(1,2)); document.write("<br />(-2,2): " + str.substr(-2,2)); document.write("<br />(1): " + str.substr(1)); document.write("<br />(-20, 2): " + str.substr(-20,2)); document.write("<br />(20, 2): " str.substr(20,2)); </script></body></html> Output: (1,2): pp (-2,2): Ap (1): pples are round, and apples are juicy. (-20, 2): Ap (20, 2): d
  • 19. substring() Description: – This method returns a subset of a String object. Syntax: – string.substring(indexA, [indexB]) Parameters: – indexA : An integer between 0 and one less than the length of the string. – indexB : (optional) An integer between 0 and the length of the string. Return Value: – The substring method returns the new sub string based on given parameters
  • 20. substring() Example: <html> <head><title>JavaScript String substring() Method</title></head><body> <script type=”text/javascript”> var str = “Apples are round, and apples are juicy.”; document.write( “(1,2): “ + str.substring(1,2)); document.write( “<br />(0,10):” + str.substring(0, 10)); document.write(“<br />(5): “ + str.substring(5)); </script></body> </html> Output: (1,2): p(0,10): Apples are (5): s are round, and apples are juicy.
  • 21. toLowerCase() Description: – This method returns the calling string value converted to lowercase. Syntax: – string.toLocaleLowerCase( ) Return Value: – Returns the calling string value converted to lowercase.
  • 22. toLowerCase() Example: <html> <head> <title>JavaScript String toLowerCase() Method </title></head><body> <script type="text/javascript"> var str = "Apples are round, and Apples are Juicy."; document.write(str.toLowerCase( )); </script></body> </html> Output: apples are round, and apples are juicy.
  • 23. toUpperCase() Description: – This method returns the calling string value converted to uppercase. Syntax: – string.toUpperCase( ) Return Value: – Returns a string representing the specified object.
  • 24. toUpperCase() Example: <html> <head> <title>JavaScript String toUpperCase() Method</title> </head> <body> <script type="text/javascript"> var str = "Apples are round, and Apples are Juicy."; document.write(str.toUpperCase( )); </script> </body> </html> Output: APPLES ARE ROUND, AND APPLES ARE JUICY.