<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <title>03stringlObject.html</title>

    <script>

        var str = "java script"//string variable

        var strObj = new String("Hellojava scripta");

        document.write("strObj.charAt(3)=" + strObj.charAt(3) + "<br/>");

        document.write("strObj.indexOf('a')=" + strObj.indexOf('a') + "<br/>");

        document.write("strObj.lastIndexOf('a')=" + strObj.lastIndexOf('a') + "<br/>");

        document.write("strObj.lastIndexOf('@')=" + strObj.lastIndexOf('@') + "<br/>");//沒有的字顯示-1

        document.write("strObj.substr(5,3)=" + strObj.substr(5, 3) + "<br/>");//第五個字開始,數三個

        document.write("strObj.substring(5,8)=" + strObj.substring(5, 9) + "<br/>");//第五個字開始,到第八個字

        document.write("strObj.split(' ')=" + strObj.split(" ") + "<br>");//空格變逗號

    </script>

</head>

<body>

 

</body>

</html>



strObj.charAt(3)=l
strObj.indexOf('a')=6
strObj.lastIndexOf('a')=16
strObj.lastIndexOf('@')=-1
strObj.substr(5,3)=jav
strObj.substring(5,8)=java
strObj.split(' ')=Hellojava,scripta

乙方 發表在 痞客邦 留言(0) 人氣()