Results 1 to 7 of 7

Thread: Splitting the string in VB5

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 1999
    Location
    Ikaalinen, Finland
    Posts
    26
    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

  2. #2
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    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.

  3. #3
    Guest
    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 .

  4. #4
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    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.

  5. #5
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Jop, do you know all those languages? Or did you use a crappy online translator?
    Oetje
    [email protected]
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  6. #6
    Guest
    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]
    **!
    [/quote]


    Nothingese:
    [/quote]
    @$*^@$ W#($*$(!@$*!#)!*( **!%**R($!
    [/quote]

  7. #7
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    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
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width