asp如何把字符串两端出现的逗号去掉

themass 2008-04-10 09:17:48
我有类似如下的字符串
字符串1=",1,2,3,4,"
字符串1="1,2,3,4,"
字符串1=",1,2,3,4"

要求处理后如下
字符串1="1,2,3,4"
字符串1="1,2,3,4"
字符串1="1,2,3,4"

处理后的字符串需要两端的不要出现逗号,用asp如何做呀
...全文
98 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
银狐被占用 2008-04-10
function replacetext(txt)
f_flag = 0
f_str = ""
f_txt = split(txt,",")
for fi = 0 to Ubound(f_txt)
if Trim(f_txt(fi)) <> "" then
f_flag = 1
if f_str <> "" then f_str = f_str & ","
f_str = f_str & f_txt(fi)
else
if f_flag = 1 And fi < Ubound(f_txt) Then
if f_str <> "" then f_str = f_str & ","
f_str = f_str & f_txt(fi)
End if
end if
Next
replacetext = f_str
end Function


将字符串传到函数据转换一下就可以了。
回复
jbj001 2008-04-10
当然也可以先用replace(str,","," "),然后trim(str),再用替换replace(str," ",",")
回复
jbj001 2008-04-10
判断一下么好了:
if left(str,1)="," then
str=mid(str,2,len(str)-1)
end if


if right(str,1)="," then
str=mid(str,1,len(str)-1)
end if
具体的话自己再调试下

回复
gingerkang 2008-04-10

a=",1,2,3,4,"
response.write mid(replace(","& a &",",",,",","),2,len(replace(","& a &",",",,",","))-2)
回复
若白师妹 2008-04-10
第一天写代码?
回复
小逗狗 2008-04-10
字符串1=left(字符串1,8)
字符串1=right(字符串1,7)
回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2008-04-10 09:17
社区公告
暂无公告