1,080
社区成员
发帖
与我相关
我的任务
分享
string ls_str[], ls_tmp
long ll_len, i
ls_tmp = '64,546876,574674456,456,237,24333' + ','
do while pos( ls_tmp, ',' ) > 0
i ++
ls_str[i] = left( ls_tmp, pos( ls_tmp, ',' ) - 1 )
ls_tmp = mid( ls_tmp, pos( ls_tmp, ',' ) + 1 )
loop
//会把64、546876、574674456、456、237、24333这6个字符串存进数组ls_str[]
for i = 1 to upperbound(ls_str)
messagebox( '', ls_str[i] )
next
如果是PB,使用pos , left , mid 加数组来实现.
string sz[]
string s = '64,546876,574674456,456,237,24333'
int i = 0
DO WHILE pos(s , ',') > 0
i = i + 1
sz[i] = left(s , pos(s , ',') - 1)
s = mid(s , pos(s , ',') + 1 , len(s))
LOOP
i = i + 1
sz[i] = s
如果是SQL SERVER,使用字符串分解函数.
/*
功能:实现split功能的函数
*/
create function dbo.fn_split
(
@inputstr varchar(8000),
@seprator varchar(10)
)
returns @temp table (a varchar(200))
as
begin
declare @i int
set @inputstr = rtrim(ltrim(@inputstr))
set @i = charindex(@seprator, @inputstr)
while @i >= 1
begin
insert @temp values(left(@inputstr, @i - 1))
set @inputstr = substring(@inputstr, @i + 1, len(@inputstr) - @i)
set @i = charindex(@seprator, @inputstr)
end
if @inputstr <> '\'
insert @temp values(@inputstr)
return
end
go
--调用
declare @s varchar(1000)
set @s='64,546876,574674456,456,237,24333'
select * from dbo.fn_split(@s,',')
drop function dbo.fn_split
/*
a
----
64
546876
574674456
456
237
24333
(所影响的行数为 6 行)
*/