[RESOLVED] php explode() equivalent in VB?
Hey guys,
I'm not sure how many of you are familiar with php (i'm sure quite a lot of you are)
I was just wondering if VB had an equivalent explode function, currently im receiving some data delimited by the | character, like below
Quote:
data1|data2|data3|data4
At the moment im trying to retrieve this data (done), then split this data up, and then enter it into array so i can do a for loop with some of the values.
I'd really appreciate it if someone could point me to the solution.
Thanks for your time,
Adam
Re: php explode() equivalent in VB?
I think you are talking about the VB6 SPLIT Function
Re: php explode() equivalent in VB?
And the mirror of Split() is Join().
Re: php explode() equivalent in VB?
Ok, thanks, that worked great guys.
But i want to change the goal posts now, the data is coming as this.
First im splitting it using the | delimiter, but then i need to split it using the : delimeter
Quote:
data1:data2|data3:data4|data5:data6|data7:data8
I need to perform some form of for loop to do that and split it again don't i? Well i've been trying that, can't seem to sort it - lol this is just basic stuff :(
Re: php explode() equivalent in VB?
Try something like
Code:
Private Sub Command1_Click()
Dim sData1 As String
Dim sData2 As String
Dim arrData1() As String
Dim arrData2() As String
Dim i As Long
sData1 = "data1:data2|data3:data4|data5:data6|data7:data8"
arrData1 = Split(sData1, "|")
sData2 = Join(arrData1)
arrData2 = Split(sData2, ":")
For i = 0 To UBound(arrData2)
MsgBox arrData2(i)
Next
End Sub
Re: php explode() equivalent in VB?
You can also use Replace() to change the colons to pipes so you can split on one delimiter if this is what you need.
Re: php explode() equivalent in VB?
Thanks for the help so far guys - its been "lightning" fast. :) :thumb:
Is their anyway of splitting the data in to two arrays
Quote:
data1:data2:|:data3:data4:|data5:data6:|:data7:data8
For example, when i've split it down to this:
Quote:
data1:data2:data3:data4:data5:data6::data7:data8
First array should include, 1, 3, 5, 7, and so on
Second array, 2, 4, 6, 8 and so on
The reason is because 1,3,5,7 include names and the other is a unique id
Re: php explode() equivalent in VB?
If your gonna use one delimiter then simply iterate Step 2. Iteration index goes to first array, index + 1 to the other.