Home > Web Front-end > JS Tutorial > Summary of using JavaScript string processing functions_javascript skills

Summary of using JavaScript string processing functions_javascript skills

WBOY
Release: 2016-05-16 18:14:54
Original
1189 people have browsed it
1. Calculate the length of the string
Copy the code The code is as follows:

var txt="Hello World!"
document.write(txt.length)

2.indexOf() method

How to use indexOf () to locate the first occurrence of a specified character in a string.
Copy code The code is as follows:



3.match() method

searches for a specific character in a string, and if found, returns this character.
Copy code The code is as follows:



4. How to replace characters in a string - replace()
Use the replace() method to replace certain characters with other characters in a string.
Copy code The code is as follows:


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template