Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2009
    Posts
    85

    Unanswered: parse with multi-delimiters

    Hello, this is a parsing function where c is a delimiter of choice(thanks PHV), can this be generalized to parse with respect to multi-delimiters, thanks (keep needing thing I do not have the skill to write)

    Function GetCSWord3(ByVal S, Indx As Integer, c As String)
    If IsNull(S) Then Exit Function
    Dim myArr
    myArr = Split(S, c)
    If Indx >= 1 And Indx <= (1 + UBound(myArr)) Then
    GetCSWord3 = Trim(myArr(Indx - 1))
    End If
    End Function

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    interesting that you should thank PHV, because he's not a member here -- as far as i know he's only on tek-tips

    are you sure you didn't mean to post over there instead?

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Apr 2009
    Posts
    85
    Thank you for responding r937, I do know what forum I am on and what forum PHV calls home, generosity (particularly resent generosity) deserves acknowledgement member or not

  4. #4
    Join Date
    Apr 2009
    Posts
    85
    Here is a generalized parsing function, call it like so:

    GetCSWord([FieldName],x, "delimiters")

    call if x times, where x is the number of string fragments to be parsed
    and delimiters are all the delimiters you want to use so e.g ",._ ", note to parse w.r.t space or tab just hit the space bar or tab key any where with in the quotes.
    And yes to declare my gratitude again to a non member thank you PHV.



    Function GetCSWord(ByVal S, Indx As Integer, Delimiters As String)
    If IsNull(S) Then Exit Function
    Dim myArr, i As Long, c As String
    c = Left(Delimiters, 1)
    For i = 2 To Len(Delimiters)
    S = Replace(S, Mid(Delimiters, i, 1), c)
    Next
    myArr = Split(S, c)
    If Indx >= 1 And Indx <= (1 + UBound(myArr)) Then
    GetCSWord = Trim(myArr(Indx - 1))
    End If
    End Function
    Last edited by Timothyl; 07-21-09 at 09:21.

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    ... and the question or problem here is?
    I'd rather be riding on the Tiger 800 or the Norton

  6. #6
    Join Date
    Apr 2009
    Posts
    85
    healdem, thanks for responding, non anymore, having got an answer elsewhere I posted back the solution as much for future beginners like me needing a solution to parsing.

  7. #7
    Join Date
    Apr 2009
    Posts
    85
    For the sake of people searching the forum in the future on parsing, here is I think is the last entry. The code above did not parse the way one would like when two delimiters were juxtaposed, like a comma and a space the following takes care of that


    Function GetCSWord(ByVal S, Indx As Integer, Delimiters As String, Optional Consecutive As Boolean = True)
    If IsNull(S) Then Exit Function
    Dim myArr, i As Long, c As String
    c = Left(Delimiters, 1)
    For i = 2 To Len(Delimiters)
    S = Replace(S, Mid(Delimiters, i, 1), c)
    Next
    If Consecutive Then
    While InStr(S, c & c): S = Replace(S, c & c, c): Wend
    End If
    myArr = Split(S, c)
    If Indx >= 1 And Indx <= (1 + UBound(myArr)) Then
    GetCSWord = Trim(myArr(Indx - 1))
    End If
    End Function

Posting Permissions

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