在Asp中如何获得以下结果?
Dim Str
Str="abc 2, def 45,fffff 110,ruele 4,"
在ASP中怎么能获取到 以上字符串中的 2 45 110 4 这四组数字呢? 它们的规律是 每组数字前面有个“ ”空格 后面有个“,”逗号。
请高手赐教!谢谢!
------解决方案--------------------
原理是:查找出第一个空格所在位置-->逗号所在位置-->截取出第一个数字-->删除第一个逗号以前的字符串
trim()去两边空格-->以此类推
------解决方案--------------------
Dim Str,str1,str2
Str="abc 2, def 45,fffff 110,ruele 4,"
str1=split(Str,",")
for i=0 to ubound(str1)
str2=trim(str1(i))
if str2<>"" then
response.write split(str2," ")(1)
end if
next
------解决方案--------------------
- VBScript code
<% Dim Str,str1,str2 Str="abc 2, def 45,fffff 110,ruele 4," str1=split(Str,",") for i=0 to ubound(str1) response.Write str1(i)&"<br>" '可以省略 response.Write right(trim(str1(i)),len(trim(str1(i)))-instr(trim(str1(i))," "))&"<br>" next 'response.write str2 %>
------解决方案--------------------
- VBScript code
<% Dim Str,str1,str2 Str="abc 2, def 45,fffff 110,ruele 4," str1=split(Str,",") for i=0 to ubound(str1) response.Write str1(i)&"<br>" response.Write right(trim(str1(i)),len(trim(str1(i)))-instr(trim(str1(i))," "))&"<br>" next 'response.write str2 %>