SlideShare a Scribd company logo
2
Most read
3
Most read
8
Most read
Prof. Neeraj Bhargava
Kapil Chauhan
Department of Computer Science
School of Engineering & Systems Sciences
MDS University, Ajmer
 String Length
 The length property returns the length of a string:
 Example
var txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var sln = txt.length;
 Output: The length property returns the length of a string:
26
 Finding a String in a String
 The indexOf() method returns the index of (the position of)
the first occurrence of a specified text in a string:
 Example
var str = "Please locate where 'locate' occurs!";
var pos = str.indexOf("locate");
 Output: The indexOf() method returns the position of the first
occurrence of a specified text:
7
 The lastIndexOf() method returns the index of
the last occurrence of a specified text in a string:
Example
var str = "Please locate where 'locate' occurs!";
var pos = str.lastIndexOf("locate");
 Output:The lastIndexOf() method returns the position of the last
occurrence of a specified text:21
 Both indexOf(), and lastIndexOf() return -1 if the text is not
found.
Example
var str = "Please locate where 'locate' occurs!";
var pos = str.lastIndexOf("John");
 Output: -1
 Both methods accept a second parameter as the starting position
for the search:
 The search() method searches a string for a specified value and
returns the position of the match:
Example
var str = "Please locate where 'locate' occurs!";
var pos = str.search("locate");
 Output: The search() method returns the position of the first
occurrence of a specified text in a string: 8
There are 3 methods for extracting a part of a string:
 slice(start, end)
 substring(start, end)
 substr(start, length)
 slice() extracts a part of a string and returns the extracted part in a
new string.
 The method takes 2 parameters: the start position, and the end
position (end not included).
 This example slices out a portion of a string from position 7 to
position 12 (13-1):
Example
var str = "Apple, Banana, Kiwi";
var res = str.slice(7, 13);
 The result of res will be: Banana
 substring() is similar to slice().
 The difference is that substring() cannot accept negative indexes.
Example
var str = "Apple, Banana, Kiwi";
var res = str.substring(7, 13);
 The result of res will be: Banana
 substr() is similar to slice().
 The difference is that the second parameter specifies
the length of the extracted part.
Example
var str = "Apple, Banana, Kiwi";
var res = str.substr(7, 6);
 The result of res will be: Banana
 A string is converted to upper case with toUpperCase():
Example
var text1 = "Hello World!";
var text2 = text1.toUpperCase();
Output: HELLO WORLD!
 A string is converted to lower case with toLowerCase():
Example
var text1 = "Hello World!";
var text2 = text1.toLowerCase();
Output: hello world!

More Related Content

PPTX
Row enumeration by Carpenter algorithm_ANIKET CHOUDHURY
अनिकेत चौधरी
 
DOC
5
satishbb
 
PPT
Headerfiles
archikabhatia
 
PPSX
Dynamic memory allocation
Moniruzzaman _
 
PPTX
Computer programming 2 Lesson 12
MLG College of Learning, Inc
 
PDF
TMPA-2017: Functional Parser of Markdown Language Based on Monad Combining an...
Iosif Itkin
 
PPT
Javascript built in String Functions
Avanitrambadiya
 
PPTX
String.pptxihugyftgrfxdf bnjklihugyfthfgxvhbjihugyfthcgxcgvjhbkipoihougyfctgf...
minifriendofyou
 
Row enumeration by Carpenter algorithm_ANIKET CHOUDHURY
अनिकेत चौधरी
 
Headerfiles
archikabhatia
 
Dynamic memory allocation
Moniruzzaman _
 
Computer programming 2 Lesson 12
MLG College of Learning, Inc
 
TMPA-2017: Functional Parser of Markdown Language Based on Monad Combining an...
Iosif Itkin
 
Javascript built in String Functions
Avanitrambadiya
 
String.pptxihugyftgrfxdf bnjklihugyfthfgxvhbjihugyfthcgxcgvjhbkipoihougyfctgf...
minifriendofyou
 

Similar to Javascript string method (20)

PPT
Strings
naslin prestilda
 
PPTX
Web Development_Sec6_kkkkkkkkkkkkkkkkkkkkkkkkkJS.pptx
samaghorab
 
PDF
Web Development_Sec6_Java secriptvvvvv.pdf
samaghorab
 
PPT
JavaScript Objects
Reem Alattas
 
PPTX
5. string
PhD Research Scholar
 
PPT
CSC128_Part_1_WrapperClassesAndStrings_CenBNcj.ppt
rani marri
 
PPTX
php string part 3
monikadeshmane
 
PPTX
Java string , string buffer and wrapper class
SimoniShah6
 
PDF
Strings in java
Kuppusamy P
 
PDF
Python String rstrip() Method.pdf
Developer Helps
 
PPTX
L14 string handling(string buffer class)
teach4uin
 
PPTX
MySQL String Functions.pptx
MayankSharma867296
 
PDF
Python Strings Methods
Mr Examples
 
PDF
JavaScript - Chapter 10 - Strings and Arrays
WebStackAcademy
 
PPS
String and string buffer
kamal kotecha
 
PPTX
Java String Handling
Infoviaan Technologies
 
PDF
Python data handling
Prof. Dr. K. Adisesha
 
PDF
Strings part2
yndaravind
 
Web Development_Sec6_kkkkkkkkkkkkkkkkkkkkkkkkkJS.pptx
samaghorab
 
Web Development_Sec6_Java secriptvvvvv.pdf
samaghorab
 
JavaScript Objects
Reem Alattas
 
CSC128_Part_1_WrapperClassesAndStrings_CenBNcj.ppt
rani marri
 
php string part 3
monikadeshmane
 
Java string , string buffer and wrapper class
SimoniShah6
 
Strings in java
Kuppusamy P
 
Python String rstrip() Method.pdf
Developer Helps
 
L14 string handling(string buffer class)
teach4uin
 
MySQL String Functions.pptx
MayankSharma867296
 
Python Strings Methods
Mr Examples
 
JavaScript - Chapter 10 - Strings and Arrays
WebStackAcademy
 
String and string buffer
kamal kotecha
 
Java String Handling
Infoviaan Technologies
 
Python data handling
Prof. Dr. K. Adisesha
 
Strings part2
yndaravind
 
Ad

More from chauhankapil (20)

PPTX
Gray level transformation
chauhankapil
 
PPTX
Elements of visual perception
chauhankapil
 
PPTX
JSP Client Request
chauhankapil
 
PPTX
Jsp server response
chauhankapil
 
PPTX
Markov decision process
chauhankapil
 
PPTX
RNN basics in deep learning
chauhankapil
 
PPTX
Introduction to generative adversarial networks (GANs)
chauhankapil
 
PPTX
Bayesian probabilistic interference
chauhankapil
 
PPTX
Jsp
chauhankapil
 
PPTX
Exception handling in java
chauhankapil
 
PPTX
Knowledge acquistion
chauhankapil
 
PPTX
Knowledge based system
chauhankapil
 
PPTX
Introduction of predicate logics
chauhankapil
 
PPTX
Types of inheritance in java
chauhankapil
 
PPTX
Representation of syntax, semantics and Predicate logics
chauhankapil
 
PPTX
Inheritance in java
chauhankapil
 
PPTX
Propositional logic
chauhankapil
 
PPTX
Constructors in java
chauhankapil
 
PPTX
Methods in java
chauhankapil
 
PPT
Circular linked list
chauhankapil
 
Gray level transformation
chauhankapil
 
Elements of visual perception
chauhankapil
 
JSP Client Request
chauhankapil
 
Jsp server response
chauhankapil
 
Markov decision process
chauhankapil
 
RNN basics in deep learning
chauhankapil
 
Introduction to generative adversarial networks (GANs)
chauhankapil
 
Bayesian probabilistic interference
chauhankapil
 
Exception handling in java
chauhankapil
 
Knowledge acquistion
chauhankapil
 
Knowledge based system
chauhankapil
 
Introduction of predicate logics
chauhankapil
 
Types of inheritance in java
chauhankapil
 
Representation of syntax, semantics and Predicate logics
chauhankapil
 
Inheritance in java
chauhankapil
 
Propositional logic
chauhankapil
 
Constructors in java
chauhankapil
 
Methods in java
chauhankapil
 
Circular linked list
chauhankapil
 
Ad

Recently uploaded (20)

PPTX
easa module 3 funtamental electronics.pptx
tryanothert7
 
PPT
Ppt for engineering students application on field effect
lakshmi.ec
 
DOCX
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
PPTX
Module2 Data Base Design- ER and NF.pptx
gomathisankariv2
 
PDF
Introduction to Data Science: data science process
ShivarkarSandip
 
PPTX
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
Natural_Language_processing_Unit_I_notes.pdf
sanguleumeshit
 
PDF
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
PDF
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
PPTX
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
PDF
Top 10 read articles In Managing Information Technology.pdf
IJMIT JOURNAL
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PPT
SCOPE_~1- technology of green house and poyhouse
bala464780
 
PPTX
Inventory management chapter in automation and robotics.
atisht0104
 
PDF
Traditional Exams vs Continuous Assessment in Boarding Schools.pdf
The Asian School
 
PDF
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
PPTX
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
flutter Launcher Icons, Splash Screens & Fonts
Ahmed Mohamed
 
easa module 3 funtamental electronics.pptx
tryanothert7
 
Ppt for engineering students application on field effect
lakshmi.ec
 
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
Module2 Data Base Design- ER and NF.pptx
gomathisankariv2
 
Introduction to Data Science: data science process
ShivarkarSandip
 
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Natural_Language_processing_Unit_I_notes.pdf
sanguleumeshit
 
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
Top 10 read articles In Managing Information Technology.pdf
IJMIT JOURNAL
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
SCOPE_~1- technology of green house and poyhouse
bala464780
 
Inventory management chapter in automation and robotics.
atisht0104
 
Traditional Exams vs Continuous Assessment in Boarding Schools.pdf
The Asian School
 
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
flutter Launcher Icons, Splash Screens & Fonts
Ahmed Mohamed
 

Javascript string method

  • 1. Prof. Neeraj Bhargava Kapil Chauhan Department of Computer Science School of Engineering & Systems Sciences MDS University, Ajmer
  • 2.  String Length  The length property returns the length of a string:  Example var txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; var sln = txt.length;  Output: The length property returns the length of a string: 26  Finding a String in a String  The indexOf() method returns the index of (the position of) the first occurrence of a specified text in a string:  Example var str = "Please locate where 'locate' occurs!"; var pos = str.indexOf("locate");  Output: The indexOf() method returns the position of the first occurrence of a specified text: 7
  • 3.  The lastIndexOf() method returns the index of the last occurrence of a specified text in a string: Example var str = "Please locate where 'locate' occurs!"; var pos = str.lastIndexOf("locate");  Output:The lastIndexOf() method returns the position of the last occurrence of a specified text:21  Both indexOf(), and lastIndexOf() return -1 if the text is not found.
  • 4. Example var str = "Please locate where 'locate' occurs!"; var pos = str.lastIndexOf("John");  Output: -1  Both methods accept a second parameter as the starting position for the search:
  • 5.  The search() method searches a string for a specified value and returns the position of the match: Example var str = "Please locate where 'locate' occurs!"; var pos = str.search("locate");  Output: The search() method returns the position of the first occurrence of a specified text in a string: 8
  • 6. There are 3 methods for extracting a part of a string:  slice(start, end)  substring(start, end)  substr(start, length)
  • 7.  slice() extracts a part of a string and returns the extracted part in a new string.  The method takes 2 parameters: the start position, and the end position (end not included).  This example slices out a portion of a string from position 7 to position 12 (13-1): Example var str = "Apple, Banana, Kiwi"; var res = str.slice(7, 13);  The result of res will be: Banana
  • 8.  substring() is similar to slice().  The difference is that substring() cannot accept negative indexes. Example var str = "Apple, Banana, Kiwi"; var res = str.substring(7, 13);  The result of res will be: Banana
  • 9.  substr() is similar to slice().  The difference is that the second parameter specifies the length of the extracted part. Example var str = "Apple, Banana, Kiwi"; var res = str.substr(7, 6);  The result of res will be: Banana
  • 10.  A string is converted to upper case with toUpperCase(): Example var text1 = "Hello World!"; var text2 = text1.toUpperCase(); Output: HELLO WORLD!  A string is converted to lower case with toLowerCase(): Example var text1 = "Hello World!"; var text2 = text1.toLowerCase(); Output: hello world!