VB6 Formatting a string Problem
My question is simple..
How do I convert a string like"445B986D2DD3B41852964ABA11408E82"
to 445B9-86D2D-D3B41-85296-4ABA1-1408E82
It should be in the format '#####-#####-#####-#####-#开发者_高级运维####-############
(the last matter does not matter)Here is a method using MOD
Dim OldStr As String
OldStr = "445B986D2DD3B41852964ABA11408E82"
Dim NewStr As String
For i = 1 To Len(OldStr)
NewStr = NewStr & Mid(OldStr, i, 1)
If i Mod 5 = 0 Then
NewStr = NewStr & "-"
End If
Next
and using STEP
For i = 1 To Len(st) Step 5
ss = ss & Mid(st, i, 5) & "-"
Next
Why don't you just add the dashes:
s = Left(s, 5) + "-" + Mid(s, 6, 5) + "-" + Mid(s, 11, 5) + "-" + Mid(s, 16, 5) _
+ "-" + Mid(s, 21, 5) + "-" + Right(s, Len(s) - 25)
You may use Mid(), Left(), Right() functions and concatenate operator (&). E.g:
dim str
str = "12345678"
str = Left(str, 2) &"-"& Mid(str, 2, 2) & "-"& Mid(str, 4, 2) & "-"&Right(str, 2)
MsgBox str ' the output will be 12-34-56-78
you can use a maskedinput textbox with that mask, but the maxlenght is 64, or i can send a supertextbox made by me with a lot of improvements
精彩评论