<script language=”JavaScript”>
var myVariable = “Hello there”;//原始字符串
var therePlace = myVariable.search(“there”);//搜索 myVariable 内是否存在 there
document.write(therePlace);//存在则输出therePlace
</script>
javascript中字符串搜索
本文介绍了一个简单的JavaScript示例,演示如何使用search方法在字符串中查找特定子串的位置。通过document.write输出子串“there”在变量myVariable中的起始位置。

被折叠的 条评论
为什么被折叠?



