——————————JavaScript中,对String字符串的一些操作——————————

时间:2021-07-10 08:42:14

—————————————————————————————————————————————————————————————————————————————————————————————

<html>

<title></title>

<head></head>
<body>
<script language="JavaScript">
var arr=new Array(7,4,7,3,2,6,2,3);
document.write("</br>"+arr.sort()+"</br>");
var str1=new String("I Love China");
var str2=new String("I Love England");
document.write("字符串str1的长度为:"+str1.length+"</br>");
document.write("返回字符串2的第5个字符是:"+str2.charAt(5)+"</br>");
document.write("检查第一个字符串China的位置:"+str1.indexOf("China")+"</br>");
document.write("把字符串中的字符变成大写字母:"+str2.toUpperCase()+"</br>");
var str3=str1.replace("China","England");
document.write("把1字符串替换为2字符串:"+str3+"</br>");
</script> </body>
</html>

————————————————————————————————————————————————————————————————————————————————————————————————————————