欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

vbs字符串操作小考题

程序员文章站 2022-04-29 09:40:20
str="a|b|c|d" 要求写一段小程序得出: a|b|c|d b|c|d|a c|d|a|b d|a|b|c 这样的结果,str长度未定,格式是上边的格式。 实现代码...
str="a|b|c|d"

要求写一段小程序得出:

a|b|c|d
b|c|d|a
c|d|a|b
d|a|b|c

这样的结果,str长度未定,格式是上边的格式。

实现代码如下:
复制代码 代码如下:

str="a|b|c|d"
call sort(str, "|")
function sort(ssource, sdelimiter)
dim i, j, n, sitems, stemp

sitems = split(ssource, sdelimiter)
for i = 0 to ubound(sitems)
for j = 0 to ubound(sitems)
n = i + j
if n > ubound(sitems) then
n = n - ubound(sitems) - 1
end if
stemp = stemp & sitems(n) & sdelimiter
next
stemp = left(stemp, len(stemp) - len(sdelimiter))
wscript.echo stemp
stemp = ""
next
end function

在一个窗口同时显示
复制代码 代码如下:

str = "a|b|c|d"
wsh.echo join(sort(str, "|"), vbcrlf)
function sort(byval s, byval d)
dim a, r(), i, j, h, index
a = split(s, d)
h = ubound(a)
redim preserve r(h)
index = len(d) + 1

for i = 0 to h
r(i) = ""
for j = i to h + i
r(i) = r(i) & d & a(j mod (h + 1))
next
r(i) = mid(r(i), index)
next

sort = r
end function

复制代码 代码如下:

str="a|b|c|d"
wscript.echo sort(str, "|")

function sort(ssource, sdelimiter)
dim i, j, n, sitems, stemp
sitems = split(ssource, sdelimiter)
n = ubound(sitems)
for i = 0 to n
for j = 0 to n
stemp = stemp & sitems((i + j) mod (n + 1)) & sdelimiter
next
stemp = left(stemp, len(stemp) - len(sdelimiter))
sort = sort & stemp & vbcrlf
stemp = ""
next
sort = left(sort, len(sort) - 1)
end function

复制代码 代码如下:

str="a|b|c|d"
msgbox sort(str, "|")

function sort(ss,sd)
dim n,i
for i=0 to ubound(split(ss,sd))
sort=sort+mid(ss+sd+ss,n+1,len(ss))+vbcrlf
n=instr(n+1,ss+sd+ss,sd)
next
end function