SlideShare a Scribd company logo
Javascript built in String Functions
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 (20)

JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
jQuery
jQueryjQuery
jQuery
Dileep Mishra
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
ivpol
 
Javascript
JavascriptJavascript
Javascript
mussawir20
 
Angularjs PPT
Angularjs PPTAngularjs PPT
Angularjs PPT
Amit Baghel
 
Javascript essentials
Javascript essentialsJavascript essentials
Javascript essentials
Bedis ElAchèche
 
DTD
DTDDTD
DTD
Kamal Acharya
 
jQuery
jQueryjQuery
jQuery
Vishwa Mohan
 
JavaScript - Chapter 7 - Advanced Functions
 JavaScript - Chapter 7 - Advanced Functions JavaScript - Chapter 7 - Advanced Functions
JavaScript - Chapter 7 - Advanced Functions
WebStackAcademy
 
ES6 presentation
ES6 presentationES6 presentation
ES6 presentation
ritika1
 
An Introduction to Redux
An Introduction to ReduxAn Introduction to Redux
An Introduction to Redux
NexThoughts Technologies
 
3.2 javascript regex
3.2 javascript regex3.2 javascript regex
3.2 javascript regex
Jalpesh Vasa
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6
Rob Eisenberg
 
JavaScript Control Statements I
JavaScript Control Statements IJavaScript Control Statements I
JavaScript Control Statements I
Reem Alattas
 
Javascript Arrow function
Javascript Arrow functionJavascript Arrow function
Javascript Arrow function
tanerochris
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
Priya Goyal
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
Shlomi Komemi
 
Form using html and java script validation
Form using html and java script validationForm using html and java script validation
Form using html and java script validation
Maitree Patel
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
Eyal Vardi
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
ivpol
 
JavaScript - Chapter 7 - Advanced Functions
 JavaScript - Chapter 7 - Advanced Functions JavaScript - Chapter 7 - Advanced Functions
JavaScript - Chapter 7 - Advanced Functions
WebStackAcademy
 
ES6 presentation
ES6 presentationES6 presentation
ES6 presentation
ritika1
 
3.2 javascript regex
3.2 javascript regex3.2 javascript regex
3.2 javascript regex
Jalpesh Vasa
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6
Rob Eisenberg
 
JavaScript Control Statements I
JavaScript Control Statements IJavaScript Control Statements I
JavaScript Control Statements I
Reem Alattas
 
Javascript Arrow function
Javascript Arrow functionJavascript Arrow function
Javascript Arrow function
tanerochris
 
Form using html and java script validation
Form using html and java script validationForm using html and java script validation
Form using html and java script validation
Maitree Patel
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
Eyal Vardi
 

Similar to Javascript built in String Functions (20)

Javascripting.pptx
Javascripting.pptxJavascripting.pptx
Javascripting.pptx
Vinod Srivastava
 
Javascript string method
Javascript string methodJavascript string method
Javascript string method
chauhankapil
 
Web Development_Sec6_kkkkkkkkkkkkkkkkkkkkkkkkkJS.pptx
Web Development_Sec6_kkkkkkkkkkkkkkkkkkkkkkkkkJS.pptxWeb Development_Sec6_kkkkkkkkkkkkkkkkkkkkkkkkkJS.pptx
Web Development_Sec6_kkkkkkkkkkkkkkkkkkkkkkkkkJS.pptx
samaghorab
 
Web Development_Sec6_Java secriptvvvvv.pdf
Web Development_Sec6_Java secriptvvvvv.pdfWeb Development_Sec6_Java secriptvvvvv.pdf
Web Development_Sec6_Java secriptvvvvv.pdf
samaghorab
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript Objects
Reem Alattas
 
Java script objects 2
Java script objects 2Java script objects 2
Java script objects 2
H K
 
14922 java script built (1)
14922 java script built (1)14922 java script built (1)
14922 java script built (1)
dineshrana201992
 
advancing in js Scripting languages pt4.pptx
advancing in js Scripting languages pt4.pptxadvancing in js Scripting languages pt4.pptx
advancing in js Scripting languages pt4.pptx
KisakyeDennis
 
CS101- Introduction to Computing- Lecture 38
CS101- Introduction to Computing- Lecture 38CS101- Introduction to Computing- Lecture 38
CS101- Introduction to Computing- Lecture 38
Bilal Ahmed
 
Ch08 - Manipulating Data in Strings and Arrays
Ch08 - Manipulating Data in Strings and ArraysCh08 - Manipulating Data in Strings and Arrays
Ch08 - Manipulating Data in Strings and Arrays
dcomfort6819
 
String, string builder, string buffer
String, string builder, string bufferString, string builder, string buffer
String, string builder, string buffer
SSN College of Engineering, Kalavakkam
 
stringstringbuilderstringbuffer-190830060142.pptx
stringstringbuilderstringbuffer-190830060142.pptxstringstringbuilderstringbuffer-190830060142.pptx
stringstringbuilderstringbuffer-190830060142.pptx
ssuser99ca78
 
L13 string handling(string class)
L13 string handling(string class)L13 string handling(string class)
L13 string handling(string class)
teach4uin
 
9781305078444 ppt ch08
9781305078444 ppt ch089781305078444 ppt ch08
9781305078444 ppt ch08
Terry Yoast
 
String handling(string class)
String handling(string class)String handling(string class)
String handling(string class)
Ravi Kant Sahu
 
String handling(string class)
String handling(string class)String handling(string class)
String handling(string class)
Ravi_Kant_Sahu
 
Java String Handling
Java String HandlingJava String Handling
Java String Handling
Infoviaan Technologies
 
1-JAVA SCRIPT. servere-side applications vs client side applications
1-JAVA SCRIPT. servere-side applications vs client side applications1-JAVA SCRIPT. servere-side applications vs client side applications
1-JAVA SCRIPT. servere-side applications vs client side applications
surajshreyans
 
Javascript strings
Javascript stringsJavascript strings
Javascript strings
Daniel Grippo
 
Javascript objects, properties and methods .pdf
Javascript objects, properties and methods .pdfJavascript objects, properties and methods .pdf
Javascript objects, properties and methods .pdf
daniljacobthomas
 
Javascript string method
Javascript string methodJavascript string method
Javascript string method
chauhankapil
 
Web Development_Sec6_kkkkkkkkkkkkkkkkkkkkkkkkkJS.pptx
Web Development_Sec6_kkkkkkkkkkkkkkkkkkkkkkkkkJS.pptxWeb Development_Sec6_kkkkkkkkkkkkkkkkkkkkkkkkkJS.pptx
Web Development_Sec6_kkkkkkkkkkkkkkkkkkkkkkkkkJS.pptx
samaghorab
 
Web Development_Sec6_Java secriptvvvvv.pdf
Web Development_Sec6_Java secriptvvvvv.pdfWeb Development_Sec6_Java secriptvvvvv.pdf
Web Development_Sec6_Java secriptvvvvv.pdf
samaghorab
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript Objects
Reem Alattas
 
Java script objects 2
Java script objects 2Java script objects 2
Java script objects 2
H K
 
14922 java script built (1)
14922 java script built (1)14922 java script built (1)
14922 java script built (1)
dineshrana201992
 
advancing in js Scripting languages pt4.pptx
advancing in js Scripting languages pt4.pptxadvancing in js Scripting languages pt4.pptx
advancing in js Scripting languages pt4.pptx
KisakyeDennis
 
CS101- Introduction to Computing- Lecture 38
CS101- Introduction to Computing- Lecture 38CS101- Introduction to Computing- Lecture 38
CS101- Introduction to Computing- Lecture 38
Bilal Ahmed
 
Ch08 - Manipulating Data in Strings and Arrays
Ch08 - Manipulating Data in Strings and ArraysCh08 - Manipulating Data in Strings and Arrays
Ch08 - Manipulating Data in Strings and Arrays
dcomfort6819
 
stringstringbuilderstringbuffer-190830060142.pptx
stringstringbuilderstringbuffer-190830060142.pptxstringstringbuilderstringbuffer-190830060142.pptx
stringstringbuilderstringbuffer-190830060142.pptx
ssuser99ca78
 
L13 string handling(string class)
L13 string handling(string class)L13 string handling(string class)
L13 string handling(string class)
teach4uin
 
9781305078444 ppt ch08
9781305078444 ppt ch089781305078444 ppt ch08
9781305078444 ppt ch08
Terry Yoast
 
String handling(string class)
String handling(string class)String handling(string class)
String handling(string class)
Ravi Kant Sahu
 
String handling(string class)
String handling(string class)String handling(string class)
String handling(string class)
Ravi_Kant_Sahu
 
1-JAVA SCRIPT. servere-side applications vs client side applications
1-JAVA SCRIPT. servere-side applications vs client side applications1-JAVA SCRIPT. servere-side applications vs client side applications
1-JAVA SCRIPT. servere-side applications vs client side applications
surajshreyans
 
Javascript objects, properties and methods .pdf
Javascript objects, properties and methods .pdfJavascript objects, properties and methods .pdf
Javascript objects, properties and methods .pdf
daniljacobthomas
 
Ad

Recently uploaded (20)

Smart Borrowing: Everything You Need to Know About Short Term Loans in India
Smart Borrowing: Everything You Need to Know About Short Term Loans in IndiaSmart Borrowing: Everything You Need to Know About Short Term Loans in India
Smart Borrowing: Everything You Need to Know About Short Term Loans in India
fincrifcontent
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18
Celine George
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
National Information Standards Organization (NISO)
 
Fatman Book HD Pdf by aayush songare.pdf
Fatman Book  HD Pdf by aayush songare.pdfFatman Book  HD Pdf by aayush songare.pdf
Fatman Book HD Pdf by aayush songare.pdf
Aayush Songare
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
How to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 SalesHow to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 Sales
Celine George
 
Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...
EduSkills OECD
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad LevelLDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDM & Mia eStudios
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
Smart Borrowing: Everything You Need to Know About Short Term Loans in India
Smart Borrowing: Everything You Need to Know About Short Term Loans in IndiaSmart Borrowing: Everything You Need to Know About Short Term Loans in India
Smart Borrowing: Everything You Need to Know About Short Term Loans in India
fincrifcontent
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18
Celine George
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
Fatman Book HD Pdf by aayush songare.pdf
Fatman Book  HD Pdf by aayush songare.pdfFatman Book  HD Pdf by aayush songare.pdf
Fatman Book HD Pdf by aayush songare.pdf
Aayush Songare
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
How to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 SalesHow to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 Sales
Celine George
 
Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...
EduSkills OECD
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad LevelLDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDM & Mia eStudios
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
Ad

Javascript built in String Functions

  • 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.