VBS string Operation Small Questions _vbs

Source: Internet
Author: User
Str= "A|b|c|d"

Required to write a small program to draw:

A|b|c|d
B|c|d|a
C|d|a|b
D|a|b|c

As a result, the str length is undefined and the format is the top form.

The implementation code is as follows:
Copy Code code as follows:

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

Display in a window at the same time
Copy Code code as follows:

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

Copy Code code as follows:

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

Copy Code code as follows:

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.