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
PPT
Headerfiles
PPSX
Dynamic memory allocation
PPTX
Computer programming 2 Lesson 12
PDF
TMPA-2017: Functional Parser of Markdown Language Based on Monad Combining an...
PPT
Javascript built in String Functions
PPTX
String.pptxihugyftgrfxdf bnjklihugyfthfgxvhbjihugyfthcgxcgvjhbkipoihougyfctgf...
Row enumeration by Carpenter algorithm_ANIKET CHOUDHURY
Headerfiles
Dynamic memory allocation
Computer programming 2 Lesson 12
TMPA-2017: Functional Parser of Markdown Language Based on Monad Combining an...
Javascript built in String Functions
String.pptxihugyftgrfxdf bnjklihugyfthfgxvhbjihugyfthcgxcgvjhbkipoihougyfctgf...

Similar to Javascript string method (20)

PPT
PPTX
Web Development_Sec6_kkkkkkkkkkkkkkkkkkkkkkkkkJS.pptx
PDF
Web Development_Sec6_Java secriptvvvvv.pdf
PPT
JavaScript Objects
PPTX
PPT
CSC128_Part_1_WrapperClassesAndStrings_CenBNcj.ppt
PPTX
php string part 3
PPTX
Java string , string buffer and wrapper class
PDF
Strings in java
PDF
Python String rstrip() Method.pdf
PPTX
L14 string handling(string buffer class)
PPTX
MySQL String Functions.pptx
PDF
Python Strings Methods
PDF
JavaScript - Chapter 10 - Strings and Arrays
PPS
String and string buffer
PPTX
Java String Handling
PDF
Python data handling
PDF
Strings part2
Web Development_Sec6_kkkkkkkkkkkkkkkkkkkkkkkkkJS.pptx
Web Development_Sec6_Java secriptvvvvv.pdf
JavaScript Objects
CSC128_Part_1_WrapperClassesAndStrings_CenBNcj.ppt
php string part 3
Java string , string buffer and wrapper class
Strings in java
Python String rstrip() Method.pdf
L14 string handling(string buffer class)
MySQL String Functions.pptx
Python Strings Methods
JavaScript - Chapter 10 - Strings and Arrays
String and string buffer
Java String Handling
Python data handling
Strings part2
Ad

More from chauhankapil (20)

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

Recently uploaded (20)

PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PDF
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
PPTX
UNIT - 3 Total quality Management .pptx
PPT
Total quality management ppt for engineering students
PPTX
Current and future trends in Computer Vision.pptx
PPT
A5_DistSysCh1.ppt_INTRODUCTION TO DISTRIBUTED SYSTEMS
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PDF
86236642-Electric-Loco-Shed.pdf jfkduklg
PPTX
Safety Seminar civil to be ensured for safe working.
PPT
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
PPTX
introduction to high performance computing
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
Visual Aids for Exploratory Data Analysis.pdf
PPTX
Information Storage and Retrieval Techniques Unit III
PPTX
Artificial Intelligence
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PDF
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
PDF
Categorization of Factors Affecting Classification Algorithms Selection
Exploratory_Data_Analysis_Fundamentals.pdf
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
UNIT - 3 Total quality Management .pptx
Total quality management ppt for engineering students
Current and future trends in Computer Vision.pptx
A5_DistSysCh1.ppt_INTRODUCTION TO DISTRIBUTED SYSTEMS
Automation-in-Manufacturing-Chapter-Introduction.pdf
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
86236642-Electric-Loco-Shed.pdf jfkduklg
Safety Seminar civil to be ensured for safe working.
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
introduction to high performance computing
R24 SURVEYING LAB MANUAL for civil enggi
Visual Aids for Exploratory Data Analysis.pdf
Information Storage and Retrieval Techniques Unit III
Artificial Intelligence
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
Categorization of Factors Affecting Classification Algorithms Selection

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!