- startsWith() and endsWith() method
- search() method
- indexOf() method
- substring() method
- substr() method
- slice() method
Let’s consider a string
str = "Welcome to GEEKS FOR GEEKS!!!". Now we have to find whether the string str starts with
startword = "Welcome" and ends with
endword = "!!!".
search() method: It checks whether a particular string is contained in another string and returns the starting index of that substring.
indexOf() method: As the name suggests, it finds the starting index of a substring in the string.
substring() method: It returns a string present between start and end index.
substr() method: It is similar to substring() method but takes start index and length of substring as parameters.
slice() method: This method returns the slices of string between any two indices in a string.
Let’s take an example of text in h1 element and check whether it starts and ends with the given substring.
- Removing occurrences of a specific character from end of a string in PHP
- How do you get the length of a string in JQuery?
- How to find sub-string between the two words using jQuery ?
- How to get text of specific option tag using jQuery?
- How to remove specific value from array using jQuery ?
- How to scroll to specific element using jQuery ?
- How to find element with specific ID using jQuery ?
- How to serialize an object to query string using jQuery ?
- How to calculate the number of words in a string using JQuery?
- How to select all elements that contains some specific CSS property using jQuery ?
- How to reload page after specific seconds in jQuery ?
- How to convert first letter of a string to upper case using jQuery ?
- How to check if URL contain certain string using PHP?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.