■作者:IPSC [2005/12/12 8:59:44]
Replace() 功能(英): Returns a string in which a specified sub-string has been replaced with another substring a specified number of times. 功能(中):替换变量或者字符串(strToBeSearched)中特定的字符(strSearchFor)为指定的字符(strReplaceWith ),甚至可以设置从第几个(start )出现的开始替换,共替换多少个(count )。 语法: Replace(strToBeSearched, strSearchFor, strReplaceWith , start , count , compare) 条件(英): strToBeSearched is a string expression containing a sub-string to be replaced; strSearchFor is the string expression to search for within strToBeSearched; strReplaceWith is the string expression to replace sub-string strSearchFor; start (optional) is the numeric character position to begin search; count (optional) is a value indicating the comparision constant.(看不懂的看例子即可理解) 例子: <% strTest = "This is an apple!" response.write Replace(strTest, "apple", "orange") %> 运行结果: This is an orange! IPSC附言:在BBSXP中用到的和例子中的一样,我的插件中也很常用此语法,至于更高级的功能,设置从第几个出现的开始替换,共替换多少个这样的功能,BBSXP中很少用。 [此帖子已被 IPSC 在 2005-12-12 9:01:14 编辑过]
【回复/版区/上篇/下篇/发贴/仅文字/HTML】 |
比较了一下,ASP中 设置从第几个出现的开始替换,但在.NET中,这个 start 却不是指第几个出现,而是指 指定字符串的第几个字符! 如: <% Dim test="01-My love is Nongnong-02-My love is Nongnong-03-My love is Nongnong-04-My love is Nongnong-05-My love is Nongnong-06-My love is Nongnong" response.write(Replace(test,"Nongnong","Pet",6,3)) %> 运行结果: love is Pet-02-My love is Pet-03-My love is Pet-04-My love is Nongnong-05-My love is Nongnong-06-My love is Nongnong
<%Dim test="01-My love is Nongnong-02-My love is Nongnong-03-My love is Nongnong-04-My love is Nongnong-05-My love is Nongnong-06-My love is Nongnong"response.write(Replace(test,"Nongnong","Pet",6,3))%>
|