- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get a part of string after a specified character in JavaScript?
To get a part of a string, string.substring() method is used in javascript. Using this method we can get any part of a string that is before or after a particular character.
str.substring()
This method slices a string from a given start index(including) to end index(excluding). If only one index is provided then the method slice the entire string from the start of the index.
syntax-1
Using this line of code we can get a part of a string after a particular character.
string.substring(string.indexOf(character) + 1);
syntax-2
Using this line of code we can get a part of a string before a particular character.
string.substring(0, string.indexOf(character));
Example
<html> <body> <script> function subStr(string, character, position) { if(position=='b') return string.substring(string.indexOf(character) + 1); else if(position=='a') return string.substring(0, string.indexOf(character)); else return string; } document.write(subStr('Tutorix & Tutorialspoint','&','a')); document.write("</br>"); document.write(subStr('Tutorix:a best e-learning platform', ':','b')); </script> </body> </html>
Output
Tutorix a best e-learning platform
- Related Articles
- Get part of a string based on a character in MySQL?
- Function that only replaces character from string after specified appearances in JavaScript
- How to truncate a string vector after a character in R?
- Java Program to get a character located at the String's specified index
- How to remove partial string after a special character in R?
- How to get the last index of an occurrence of the specified value in a string in JavaScript?
- How to get the first index of an occurrence of the specified value in a string in JavaScript?
- Left pad a String with a specified character in Java
- How to get a number of days in a specified month using JavaScript?
- How to replace a part of the string (domain name after @) using MySQL?
- PHP – How to get the selected part of a string using mb_substr()?
- Print the string after the specified character has occurred given no. of times in C Program
- String function to replace nth occurrence of a character in a string JavaScript
- Creating String Object from certain part of a character Array in Java
- How to count the number of occurrences of a character in a string in JavaScript?

Advertisements