Home > Web Front-end > JS Tutorial > Methods for intercepting, splicing, and replacing characters

Methods for intercepting, splicing, and replacing characters

一个新手
Release: 2017-10-02 09:45:50
Original
1705 people have browsed it

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>截取,拼接字符串</title>
<script type="text/javascript">
var str = "abc八dccef维jaagk研sew修wwq学rrt院mn";
/* 1.挨个从str中获取 八维研修学院 这几个字符,将获取的单个字符再拼接成完整的字符串 */
document.write("1. 挨个
截取字符
:"+"<br/><br/>");
var bwie1 = document.write(str.
substring
(3,4)+"  ");
var bwie2 = document.write(str.
substring
(9,10)+"  ");
var bwie3 = document.write(str.
substring
(15,16)+"  ");
var bwie4 = document.write(str.
substring
(19,20)+"  ");
var bwie5 = document.write(str.
substring
(23,24)+"  ");
var bwie6 = document.write(str.
substring
(27,28)); 
       
var n = document.write("<br/><br/><br/>"+"2.
拼接字符串
:<br/><br/>");
var newStr = document.write(str.substring(3,4).
concat
(
str.substring(9,10),
str.substring(15,16),
str.substring(19,20),
str.substring(23,24),
str.substring(27,28))
);
Copy after login
/* 2.使用字符串替换 replace() 的方式获取 八维研修学院 字符串 */
var r = document.write("<br/><br/><br/>"+"3.
替换字符串
:<br/><br/>");
var new_replace = document.write( str.
replace
(str,"八维研修学院"));
</script>
</head>
<body>
</body>
</html>
Copy after login

The above is the detailed content of Methods for intercepting, splicing, and replacing characters. For more information, please follow other related articles on the PHP Chinese website!

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