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
标签:
vbs,字符串

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
内蒙古资源网 Copyright www.nmgbbs.com

评论“vbs字符串操作小考题”

暂无“vbs字符串操作小考题”评论...