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

Methods for intercepting, splicing, and replacing characters

一个新手
一个新手Original
2017-10-02 09:45:501632browse

<!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))
);
/* 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>

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!

Statement:
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