Имеем текст:
АААА1
АААА2
ББББ1
ББББ2
ББББ2
ВВВВ3
ВВВВ4
ВВВВ6
ВВВВ5
ВВВВ1
AAAA3
AAAA1
и т.д.
как мне сгруппировать их в строки
АААА1 АААА2
ББББ1 ББББ2 ББББ2
ВВВВ3 ВВВВ4 ВВВВ6 ВВВВ5 ВВВВ1
AAAA3 AAAA1
Gmp писал(а):Как делается такое
Dim strQ As String, strOut As String
Dim strA() As String
Dim i As Integer
strQ = "AAAA AAAA AAAA BBBB BBBB BBBB BBBB AAAA AAAA CCCC CCCC DDDD DDDD"
strA = Split(strQ, " ")
strOut = strA(0)
For i = 1 To UBound(strA)
If (strA(i) = Right$(strOut, Len(strA(i)))) Then
strOut = strOut & " " & strA(i)
Else
strOut = strOut & vbCrLf & strA(i)
End If
Next i
strQ = "AAAA AAAA AAAA BBBB BBBB BBBB BBBB AAAA AAAA CCCC CCCC DDDD DDDD "
Private Sub Form_Load()
Dim strQ As String
Dim strA() As String
Dim x, q
strQ = "AAAA AAAA AAAA BBBB BBBB BBBB SSSS BBBB AAAA AAAA CCCC CCCC DDDD DDDD EEEE DDDD AAAA SSSS "
strA = Split(strQ, " ")
x = 1
Do Until x = UBound(strA)
For q = UBound(strA) To x Step -1
If strA(q) < strA(q - 1) Then swap strA(q), strA(q - 1)
Next q
x = x + 1
Loop
For q = 1 To UBound(strA) - 1
If q = UBound(strA) - 1 Then
If Left$(strA(q), 4) = Left$(strA(q + 1), 4) Then
Text1.Text = Text1.Text & strA(q) & " " & strA(q + 1)
Exit For
Else
Text1.Text = Text1.Text & strA(q) & vbCrLf & strA(q + 1)
Exit For
End If
End If
If Left$(strA(q), 4) = Left$(strA(q + 1), 4) Then Text1.Text = Text1.Text & strA(q) & " " Else Text1.Text = Text1.Text & strA(q) & vbCrLf
Next q
End Sub
Sub swap(a As String, b As String)
Dim ab(2)
ab(1) = a
ab(2) = b
a = ab(2)
b = ab(1)
End Sub
Sub swap(a As String, b As String)
Dim ab(2)
ab(1) = a
ab(2) = b
a = ab(2)
b = ab(1)
End Sub
SWAP variable1, variable2
Usage Notes
■ SWAP is an assignment statement that exchanges the values of two
variables.
■ Any type of variable can be swapped (integer, long, single
precision, double precision, string, currency, or record). However,
if the two variables are not exactly the same type, BASIC generates
the error message, "Type mismatch."
Private Sub Swap(ByRef S1 As String, ByRef S2 As String)
Dim S3 As String
S3 = S1
S1 = S2
S2 = S3
End Sub
Сейчас этот форум просматривают: AhrefsBot, Google-бот и гости: 125