|
-
Oct 8th, 2000, 05:41 AM
#1
Thread Starter
Junior Member
Hi again,
I have VB5 Enterprise Edition but as I have been exploring the manual, it doesn't support Split() -function which divides the string to array elements. So, is there any way to do the splitting?
- Ville
......................
Ville Mattila
-
Oct 8th, 2000, 05:48 AM
#2
Frenzied Member
I believe this works:
Code:
Private Sub Mysplit(Source, searchs As String, ByRef arr() As String)
Dim pos As Long, pos2 As Long, x As Long
pos = 0
If Right(Source, Len(searchs)) = searchs Then
Source = Mid(Source, 1, Len(Source) - Len(searchs))
End If
Do
pos = InStr(pos + 1, Source, searchs, vbTextCompare)
If pos = 0 Then Exit Do
ReDim Preserve arr(x)
arr(x) = Mid(Source, pos + 1, pos + Len(searchs) - 2)
x = x + 1
Loop
End Sub
'USAGE:
Mysplit "hoi|jop|hoi|haha|", "|", myarr()
I wrote it myself without testing it so it may contain bugs 
[/code]
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Oct 8th, 2000, 10:52 AM
#3
If you prefer the original thing:
Code:
' #VBIDEUtils#*************************************************
' * Programmer Name : Waty Thierry
' * Web Site :
' *www.geocities.com/ResearchTriangle/6311/
' * E-Mail : [email protected]
' * Date : 25/11/98
' * Time : 12:06
' * Module Name : clsIndent
' * Module Filename : Indent.cls
' * Procedure Name : Split
' * Parameters :
' * ByVal sIn As String
' * sOut() As String
' * Optional sDelim As String
' * Optional nLimit As Long = -1
' * Optional bCompare As VbCompareMethod = vbBinaryCompare
' ***********************************************************
' * Comments : Split a string into a variant array
' * This is the equivalent of the VB6 function
' * There are two ways to get the result:
' * 1) Read the sout() array, since it's passed in by Reference
' * 2) Read the return value
' * If no delimiter is provided, the default of " " is used,
' * just like in VB6
' * If the input string does not contain the delimiter,
' * an array with one element -- the input string --
' * is returned, just like in VB6
' **************************************************************
Public Function Split(ByVal Sin As String, sOut() As String, _
Optional sDelim As String, Optional nLimit As Long = -1, _
Optional bCompare As VbCompareMethod = vbBinaryCompare) As _
Variant
Dim sRead As String, nC As Integer
If sDelim = "" Then sDelim = " "
If InStr(Sin, sDelim) = 0 Then
ReDim sOut(0) As String
sOut(0) = Sin
Split = sOut
Exit Function
End If
sRead = ReadUntil(Sin, sDelim, bCompare)
Do
ReDim Preserve sOut(nC)
sOut(nC) = sRead
nC = nC + 1
If nLimit <> -1 And nC >= nLimit Then Exit Do
sRead = ReadUntil(Sin, sDelim)
Loop While sRead <> "~TWA"
ReDim Preserve sOut(nC)
sOut(nC) = Sin
Split = sOut
End Function
Private Function ReadUntil(ByRef Sin As String, sDelim As _
String, Optional bCompare As VbCompareMethod = _
vbBinaryCompare) As String
Dim nPos As String
nPos = InStr(1, Sin, sDelim, bCompare)
If nPos > 0 Then
ReadUntil = Left(Sin, nPos - 1)
Sin = Mid(Sin, nPos + Len(sDelim))
Else
ReadUntil = "~TWA"
End If
End Function
Jop désole, mais lui est également bon pour savoir la fonction fendue reguliere. Nice que vous etes ecriture vous possédez le code dehors cependant .
-
Oct 8th, 2000, 12:04 PM
#4
Frenzied Member
Jop désole, mais lui est également bon pour savoir la fonction fendue reguliere. Nice que vous etes ecriture vous possédez le code dehors cependant .
I'm dutch man not french!
I was able to figure a bit out what you meant, so here's my reply in french
Mais s'il vous plaît, prochaine réponse de temps dans hollandais ou en anglais  J'ai déjà noté quelques imperfections, et pas ai su qu'il y avait une fonction fendue déjà. Merci pour préciser cependant!
German:
Aber bitte, folgende Zeitantwort entweder auf holländisch oder auf englisch  Ich beachtete bereits einige Fehler und nicht wußte, daß es eine aufgeteilte Funktion bereits gab. Dank für zwar unterstreichen!
and maybe in Portuguese too?
Mas por favor, resposta seguinte do tempo em holandês ou em inglês  Eu observei já algumas falhas, e não soube que havia uma função rachada já. Agradecimentos para indicar though!
oh, and for the spanish people here:
Pero por favor, respuesta siguiente del tiempo en holandés o en inglés  Noté ya algunos defectos, y no sabía que había una función partida ya. Gracias por precisar sin embargo!
oh and you italians, don't feel left in the dark!
Ma prego, risposta seguente di tempo in olandese o in inglese  Già ho notato alcuni difetti e che non ho saputo che ci era già una funzione spaccata. Ringraziamenti per precisare comunque!
I could say it in dutch too but my hands hurt from typing man 
Anyway, have a nice day!
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Oct 8th, 2000, 01:30 PM
#5
Fanatic Member
Jop, do you know all those languages? Or did you use a crappy online translator?
-
Oct 8th, 2000, 01:41 PM
#6
-
Oct 8th, 2000, 02:37 PM
#7
Frenzied Member
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
|