当前位置: 移动技术网 > IT编程>脚本编程>VBScript > vbs字符串操作小考题

vbs字符串操作小考题

2017年12月08日  | 移动技术网IT编程  | 我要评论
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

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网