Hej, varför går inte denna: Varför använda Split? VB 6 version: Sisodärja:)split, array
(ppath = "värde1" "värde2" "värde3" "värde4")
<code>
Dim tmp() as string
Dim i as long
tmp = Split(pPath)
For i = 0 To UBound(tmp)
List1.AddItem tmp(i)
Next
</code>Sv: split, array
VB 5 version:
<code>
Public Function SplitString(Value As String, Prefix As String, Suffix As String, Optional Compare As Long = vbBinaryCompare) As Variant
Dim Result As Variant
Dim Size As Long
Dim Count As Long
Dim PrefixPos As Long
Dim SuffixPos As Long
Dim PrefixLength As Long
Dim SuffixLength As Long
If Len(Value) > 0 Then
Size = 1
ReDim Result(1 To Size)
PrefixLength = Len(Prefix)
SuffixLength = Len(Suffix)
Do
PrefixPos = InStr(SuffixPos + SuffixLength, Value, Prefix, Compare) + PrefixLength
If PrefixPos > PrefixLength Then
SuffixPos = InStr(PrefixPos, Value, Suffix, Compare)
If SuffixPos > 0 Then
Count = Count + 1
If Count > Size Then
Size = Size * 2
ReDim Preserve Result(1 To Size)
End If
Result(Count) = Mid(Value, PrefixPos, SuffixPos - PrefixPos)
Else
Exit Do
End If
Else
Exit Do
End If
Loop
If Count Then
ReDim Preserve Result(1 To Count)
SplitString = Result
End If
End If
End Function
Sub TestSplitString()
Dim Text As String
Dim Data As Variant
Dim Index As Long
Text = """Network Associates Log Service"" ""AlertManager"" ""AVExch32Service"" ""AVUPDService"" ""Outbreak Manager"""
Data = SplitString(Text, """", """")
If IsArray(Data) Then
For Index = LBound(Data, 1) To UBound(Data, 1)
Debug.Print Data(Index)
Next
End If
End Sub
</code>Sv: split, array
<code>
Public Function SplitString(Value As String, Prefix As String, Suffix As String, Optional Compare As vbCompareMethod = vbBinaryCompare) As String()
Dim Result() As String
Dim Size As Long
Dim Count As Long
Dim PrefixPos As Long
Dim SuffixPos As Long
Dim PrefixLength As Long
Dim SuffixLength As Long
If Len(Value) > 0 Then
Size = 1
ReDim Result(1 To Size)
PrefixLength = Len(Prefix)
SuffixLength = Len(Suffix)
Do
PrefixPos = InStr(SuffixPos + SuffixLength, Value, Prefix, Compare) + PrefixLength
If PrefixPos > PrefixLength Then
SuffixPos = InStr(PrefixPos, Value, Suffix, Compare)
If SuffixPos > 0 Then
Count = Count + 1
If Count > Size Then
Size = Size * 2
ReDim Preserve Result(1 To Size)
End If
Result(Count) = Mid(Value, PrefixPos, SuffixPos - PrefixPos)
Else
Exit Do
End If
Else
Exit Do
End If
Loop
If Count Then
ReDim Preserve Result(1 To Count)
SplitString = Result
End If
End If
End Function
Sub TestSplitString()
Dim Text As String
Dim Index As Long
Dim Data() As String
Text = """Network Associates Log Service"" ""AlertManager"" ""AVExch32Service"" ""AVUPDService"" ""Outbreak Manager"""
Data = SplitString(Text, """", """")
For Index = LBound(Data, 1) To UBound(Data, 1)
Debug.Print Data(Index)
Next
End Sub
</code>Sv: split, array
Tack ska du ha för den, ordnade det jag ville ha:)
Nu ska jag bara kunna byta ut den strängen i filen...men det får bli en annan story:)