现在的位置: 网页制作教程网站制作教程 >正文
asp语言基础教程

Replace函数介绍

发表于2017/1/31 网站制作教程 0条评论 ⁄ 热度 1,891℃

Replace函数格式是Replace(string ,find ,replacewith [,start] [,count] [,compare] ),本文是关于Replace函数的介绍。

Replace 函数用于将“string 字符串”中的“find 子字符串”替换为“replacewith 字符串”。 

string 原字符串(可以是字符串表达式)。
find 需要被替换的子字符串。
replacewith 用于替换的字符串。
start 返回结果的开始位置(函数返回从 start 位置开始的字符串,start 位置前面的字符串将被舍弃)。
可选参数,默认是 1。
count 执行子字符串替换的次数。
可选参数,默认值为 -1,表示进行所有可能的替换。
如果指定了 count 参数,则一定要有 start 参数。
compare 匹配模式(字符串比较类型),0 表示二进制比较,1 表示忽略大小写的文本比较。
可选参数,默认为 0。
如果指定了 compare 参数,则一定要有 start 参数 及 count 参数。

Replace 函数有下列返回值:

string 为零长度 零长度字符串 ("")。
string 为 Null 错误。
find 为零长度 string 副本。
replacewith 为零长度 删除 所有 find 字符串后的 string 副本。
start > Len(string) 零长度字符串 ("")。
count 为 0 string 副本。

使用示例:

<%
Response.Write Replace("we_bym" , "we_" , "We")	'结果为: Webym
Response.Write Replace("we_bym - wE_bym" , "we_" , "We" )	'结果为: Webym - wE_bym,区分大小写
Response.Write Replace("we_bym - we_bym" , "we_" , "We" , 4)	'结果为: bym - Webym,从第4个字符位置开始
Response.Write Replace("we_b - we_b - we_b" , "we_" , "We" , 1 , 2)	'结果为: Web - Web - we_b,执行2次替换
Response.Write Replace("we_b - wE_b - wE_b" , "we_" , "wE" , 1 , -1 , 1)	'结果为: Web - Web - Web,忽略大小写
%>
  • 暂无评论