亲宝软件园·资讯

展开

vbs字符串 vbs字符串操作小考题

人气:0
想了解vbs字符串操作小考题的相关内容吗,在本文为您仔细讲解vbs字符串的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:vbs,字符串,下面大家一起来学习吧。
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

加载全部内容

相关教程
猜你喜欢
用户评论