asp 去除最后一个逗号为空字符串的代码

简介:

asp中怎么替换最后一个逗号为空字符串 
举例 aaa,bbb,ccc,eee, 这个字符串 

怎么让最后一个逗号变没,其他的不变啊 
问题补充:举例 aaa,bbb,ccc,eee, 这个字符串 

怎么让最后一个逗号变没,其他的不变啊 
如果是aaa,bbb,ccc,eee则不做修改

 

代码如下:

<% 
str="aaa,bbb,ccc,eee," 
if right(str,1)="," then 
str=left(str,len(str)-1) 
end if 
%> 

asp Right 函数 可从字符串右边返回指定数目的字符。

提示:要确定 string 参数中的字符数目,使用 Len 函数 

提示:还可以参考下Left函数 

语法 
Right(string,length) 

参数 描述 
string 
必选项。字符串表达式,其最右边的字符被返回。 
length 
必选项。数值表达式,指明要返回的字符数目。如果为 0,返回零长度字符串;如果此数大于或等于 string 参数中的所有字符数目,则返回整个字符串。

 

代码实例一:

dim txttxt="This is a beautiful day!" 
response.write(Right(txt,11)) 
输出:utiful day! 

代码实例二:

dim txttxt="This is a beautiful day!" 
response.write(Right(txt,100)) 
输出:This is a beautiful day! 

代码实例三:

dim txt,xtxt="This is a beautiful day!"x=Len(txt) 
response.write(Right(txt,x)) 
输出:This is a beautiful day! 


本文转自 gutaotao1989 51CTO博客,原文链接:http://blog.51cto.com/taoyouth/1230888

相关文章
|
11月前
|
开发框架 .NET Apache
301重定向代码合集(iis,asp,php,asp.net,apache)
301重定向代码合集(iis,asp,php,asp.net,apache)
275 0
|
前端开发 .NET 开发框架