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
Printable View
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
I believe this works:
I wrote it myself without testing it so it may contain bugs :)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()
[/code]
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 :rolleyes:.
I'm dutch man :) not french!Quote:
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 was able to figure a bit out what you meant, so here's my reply in french
German:Quote:
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!
and maybe in Portuguese too?Quote:
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!
oh, and for the spanish people here:Quote:
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 you italians, don't feel left in the dark!Quote:
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!
I could say it in dutch too but my hands hurt from typing man :(Quote:
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!
Anyway, have a nice day!
Jop, do you know all those languages? Or did you use a crappy online translator?
English:
[/quote]
Crappy online translator, I assume.
[/quote]
Chinese:
[/quote]
We xiang sh tao ian de vang shang de fan i qi.
[/quote]
French:
[/quote]
Je pense c'est "crappy online translator"
<I think it's "---">
[/quote]
Smilese:
[/quote]
:(:eek::mad: :(:(:rolleyes:**!
[/quote]
Nothingese:
[/quote]
@$*^@$ W#($*$(!@$*!#)!*( **!%**R($!
[/quote]
Oetje
Dutch:
nee natuurlijk niet :)
http://babelfish.altavista.com is het sleutelwoord :)
Maar ik raadt je de Babylon Translator aan, kan je vinden op http://www.tucows.com
english
No ofcourse not :)
http://babelfish.altavista.com the keyword :)
But I recommend the Babylon Translator, you can find it at http://www.tucows.com
Ok, and can start over translating all this, but it's getting a chit-chat post now so let's get back to work ;)