小白教程
所有教程
关于
Search
172.70.100.206
172.70.100.206
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Func replace”的源代码
本页内容
上一节:
Func_mid
下一节:
Func_right
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:Replace}}[[Category:vbscript ref functions|88]] = VBScript Replace 函数 = [[vbscript ref functions|完整的 VBScript 参考手册]] Replace 函数使用另一个字符串替换字符串的指定部分指定的次数。 === 语法 === <pre> Replace(string,find,replacewith[,start[,count[,compare]]]) </pre> {| class="table table-striped table-hover" !width="50%"| 参数 !width="50%"| 描述 |- | string | 必需。被搜索的字符串。 |- | find | 必需。将被替换的字符串部分。 |- | replacewith | 必需。用于替换的子字符串。 |- | start | 可选。指定的开始位置。默认值是 1。起始位置之前的所有字符将被删除。 |- | count | 可选。规定要执行的替换的次数。 默认值是 -1,表示进行所有可能的替换。 |- | compare | 可选。规定要使用的字符串比较类型。默认是 0。 可采用下列的值: * 0 = vbBinaryCompare - 执行二进制比较 * 1 = vbTextCompare - 执行文本比较 |} == 实例 1 == 把单词 "beautiful" 替换为 "fantastic": <sample title="" desc="" lang="vb" hererun="1"> <script type="text/vbscript"> txt="This is a beautiful day!" document.write(Replace(txt,"beautiful","fantastic")) </script> </sample> 以上实例输出结果: <sample title="" desc="" lang="vb" hererun="1"> This is a fantastic day! </sample> == 实例 2 == 把字母 "i" 替换为 "##": <sample title="" desc="" lang="vb" hererun="1"> <script type="text/vbscript"> txt="This is a beautiful day!" document.write(Replace(txt,"i","##")) </script> </sample> 以上实例输出结果: <sample title="" desc="" lang="vb" hererun="1"> Th##s ##s a beaut##ful day! </sample> == 实例 3 == 把字母 "i" 替换为 "##",从位置 15 开始: 请注意,位置 15 之前的所有字符都会被删除。 <sample title="" desc="" lang="vb" hererun="1"> <script type="text/vbscript"> txt="This is a beautiful day!" document.write(Replace(txt,"i","##",15)) </script> </sample> 以上实例输出结果: <sample title="" desc="" lang="vb" hererun="1"> t##ful day! </sample> == 实例 4 == 从位置 1 开始,把前 2 个字母 "i" 替换为 "##": <sample title="" desc="" lang="vb" hererun="1"> <script type="text/vbscript"> txt="This is a beautiful day!" document.write(Replace(txt,"i","##",1,2)) </script> </sample> 以上实例输出结果: <sample title="" desc="" lang="vb" hererun="1"> Th##s ##s a beautiful day! </sample> == 实例 5 == 把字母 "t" 替换为 "##",采用文本和二进制比较: <sample title="" desc="" lang="vb" hererun="1"> <script type="text/vbscript"> txt="This is a beautiful day!" document.write(Replace(txt,"t","##",1,-1,1) & "<br />") document.write(Replace(txt,"t","##",1,-1,0)) </script> </sample> 以上实例输出结果: <sample title="" desc="" lang="vb" hererun="1"> ##his is a beau##iful day! This is a beau##iful day! </sample> [[vbscript ref functions|完整的 VBScript 参考手册]]
返回至“
Func replace
”。
上一节:
Func_mid
下一节:
Func_right