|
-
Jun 5th, 2002, 02:15 AM
#1
Thread Starter
New Member
VB String Split
Hi,
I have one String array like this.....
str(0)=msg1/msg2/msg3/msg4
str(1)=msg1/msg2/msg5
str(2)=msg1/msg2/msg6/msg7
str(3)=msg1/msg2/msg8
here i want to split the string array....and store like this......
i want to store msg1/msg2 in one string........after msg2 i want to store another string ...how can i do it.....anybody know about it....plz tell me.....
thanks in advance...
kavi_k
-
Jun 5th, 2002, 02:26 AM
#2
Retired VBF Adm1nistrator
So would this be correct :
str(n)=msg0/msg1/msg2/msg3/msg4/...msgn-1/msgn
You then want to split up as follows :
msg0/msg1 , msg2/msg3 , msg4/msg5 ... msgn-1/msgn
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Jun 5th, 2002, 02:56 AM
#3
Retired VBF Adm1nistrator
Christ I must still be asleep this morning.
This is taking way longer than it should.
Anyway, this is almost it :
VB Code:
Private Function split2(ByVal strString As String, ByVal strDelimeter As String) As String()
Dim strTemp() As String: strTemp = Split(strString, strDelimeter)
Dim i As Long, n As Long, arrRetVal() As String: ReDim arrRetVal(UBound(strTemp))
For i = 2 To UBound(strTemp) + 1 Step 2
arrRetVal(i - 2) = strTemp(i - 2) & "/" & strTemp(i - 1)
Next
split2 = arrRetVal
End Function
Private Sub Form_Load()
Dim x As String, y() As String, i As Long
x = "a/b/c/d/e/f/g/h"
y = split2(x, "/")
For i = 0 To UBound(y)
Debug.Print y(i)
Next
End Sub
That does the splitting the way you want it, but it leaves in a black space in every second index of the array.
I'll fix that in a few mins.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Jun 5th, 2002, 03:06 AM
#4
Retired VBF Adm1nistrator
End result :
VB Code:
Private Function split2(ByVal strString As String, ByVal strDelimeter As String) As String()
Dim strTemp() As String: strTemp = Split(strString, strDelimeter)
Dim i As Long, n As Long, arrRetVal() As String: ReDim arrRetVal((UBound(strTemp) - 1) / 2)
For i = 0 To UBound(strTemp) - 1
arrRetVal(n) = strTemp(i) & "/" & strTemp(i + 1)
If i Mod 2 = 0 Then
n = n + 1
End If
Next
split2 = arrRetVal
End Function
Private Sub Form_Load()
Dim x As String, y() As String, i As Long
x = "a/b/c/d/e/f/g/h"
y = split2(x, "/")
For i = 0 To UBound(y)
Debug.Print y(i)
Next
End Sub
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Jun 5th, 2002, 03:11 AM
#5
Addicted Member
why dont you use split function from VB .
something like this :
VB Code:
dim sP() as String
dim x as String
x = "a/b/c/d/"
sP = Split(x,"/")
that will result :
sP(0) = a
sP(1) = b
and etc...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|