<!DOCTYPE html>
<html>
<head>
<title>字符串操作函数</title>
<mate charest="utf-8"> <!-- 设置编码格式,以免乱码; -->
<script type="text/javascript">
var text='hello worid i like you';
// length:计算字符串长度;
// document.write(text.length);
// charAt(数字):返回指定索引位置的字符。
// document.write(text.charAt(0));
//indexOf();获取子字符串索引开始位置;
// document.write(text.indexOf('i'))
//lastIndexOf();指出最后一个子字符串开始的位置;
// document.write(text.lastIndexOf('k'))
// substring(开始,结束);返回一个子字符串;
// document.write(text.substring(2,3));
// substr(开始,长度);返回一个子字符串;
// document.write(text.substr(2,3));
// replace('要的字被替换符串','替换成的字符串');
// document.write(text.replace('you','php中文网'));
// concat();连接两个或多个字符串;
// var a='你的名字' ;
// var b='luxiansheng';
// document.write(text.concat(' ',a,' ',b));
</script>
</head>
<body>
</body>
</html>
<!-- length:计算字符串长度; -->
<!-- charAt(数字):返回指定索引位置的字符。 -->总结:
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号