Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  Asp.net  >  正文 ASP Replace 字符替换详解

ASP Replace 字符替换详解

发布时间:2016-09-23   编辑:www.jquerycn.cn
jquery中文网为您提供ASP Replace 字符替换详解等资源,欢迎您收藏本站,我们将为您提供最新的ASP Replace 字符替换详解资源
replace是用来替换字符或字符串的这个函数在asp中很好用,下面我来介绍一下此函数的用法。

title=replace(title,"DF","SD",1,-1,1)
replace函数参数详解:
参数1:源字符串
参数2:要被替换的字符
参数3:新的字符
参数4:值为1,指定从第一个字符开始搜索该字符串
参数5:值为-1 指定每一个子串都要被替换
参数6:值为1 指定字符串的比较不区分大小写。


vbscript中replace()详细说明:

功能:在字符串中查找,替代指定的字符串.
格式:replace(strtobesearched,strsearchfor,strreplacewith [,start[,count[,compare]]])
参数:strtobesearched是字符串; strsearchfor是被查找的子字符串;strreplacewith 是用来替代的子字符串.start,count,compare 是任意选项.

例子:

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy5759')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy5759>

<%
strtest="this is an apple."
response.write replace(strtest,”apple”,”orange”)
%>

实例

下面一个就是替换“'”为“''”

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy6221')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy6221>

Function strReplace(Str)
 dim tempcheckstr
 tempcheckstr=Str
 If Isnull(tempcheckstr) Then
  strReplace = ""//这里要注册,如果字符串为空,那replace装会出错
  Exit Function
 End If
 strReplace = Replace(tempcheckstr,"'","''")
End Function


下面就是将关键词加链接

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy8521')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy8521>

function insertLink(str,key,url)
   if str<>"" then
 str=replace(str,key,"<a href="&url&">"&key&"</a>"
   end if
   insertLink=str
end function

asp使用正则表达式的replace

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy7290')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy7290>

Set regEx = New RegExp
regEx.Pattern = reg  '正则表达式
regEx.IgnoreCase = True '是否忽略大小写
regEx.Global = True
newStr= regEx.Replace(oldStr,newPart) 'reg被替换成newPart
Set regEx = Nothing

Replace替换忽略大小写

Replace(expression, find, replacewith[, start[, count[, compare]]])   原理同上,count是指替换次数,-1为全部替换

您可能感兴趣的文章:
mysql replace的用法(替换指定字段字符串)
ASP Replace 字符替换详解
mysql使用replace函数进行字符串替换
js replace函数用法详解
asp html转换字符程序
Jquery replace 字符替换实现代码
python怎么替换字符串的内容
Python replace()函数:替换字符串中的某个字符
mysql获得一个字符串中某一个字符出现次数的语句
asp 过滤简单html代码程序

[关闭]