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如何做呀
...全文
220 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
银狐被占用 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
  • 打赏
  • 举报
回复
字符串1=left(字符串1,8)
字符串1=right(字符串1,7)
若白师妹 2008-04-10
  • 打赏
  • 举报
回复
第一天写代码?

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧