<script type="text/javascript"> var str = "W3Schools is great!" document.write(str.match("great")) </script>
<p>This example tests if a string contains a specified word. If the word is found it returns the word.</p>
</body> </html>
取子字符串的例子:
<html> <body>
<script type="text/javascript"> var str="W3Schools is great!" document.write(str.substr(2,6)) document.write("<br /><br />") document.write(str.substring(2,6)) </script>
<p> The substr() method returns a specified part of a string. If you specify (2,6) the returned string will be from the second character (start at 0) and 6 long. </p>
<p> The substring() method also returns a specified part of a string. If you specify (2,6) it returns all characters from the second character (start at 0) and up to, but not including, the sixth character. </p>
</body> </html>
转换字符串的大小写
<html> <body>
<script type="text/javascript"> var str=("Hello JavaScripters!") document.write(str.toLowerCase()) document.write("<br>") document.write(str.toUpperCase()) </script>