Results 1 to 5 of 5

Thread: String Parsing Question? [resolved]

  1. #1

    Thread Starter
    Addicted Member Para80d's Avatar
    Join Date
    Oct 2003
    Location
    Denton, TX
    Posts
    160

    String Parsing Question? [resolved]

    Howdy all!

    I'm trying to get some commands from a seperate application that i wrote. Here's the string i need to parse

    LRK::5.5.5.5::KIF::VERS::GET

    where the "::" are the seperators. Ok, i'm doing a Split command

    temp_string = Split(Text1.Text, "::")

    So now temp_string is an array. Now, my question is, is there a way to creat a function or something in a module that will split that up? is it possible to pass arrays in VB? don't think i've ever done it before...

    if you need more detail just ask.. thanks!!
    Last edited by Para80d; Dec 1st, 2003 at 04:47 PM.
    C++/VB6&.NET/QBasic/HTML/PHP/MySQL/SQLServer2k

    I'm the guy your little brother looks a lot alike. Tell your mom i said thanks.

    naked in vegas

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    VB Code:
    1. Private Sub Form_Load()
    2.    
    3.     Dim AnArray() As String
    4.     Const A_STRING = "LRK::5.5.5.5::KIF::VERS::GET"
    5.     AnArray = SplitString(A_STRING)
    6.    
    7. End Sub
    8.  
    9. Public Function SplitString(strInput As String) As String()
    10.  
    11.     SplitString = Split(strInput, "::")
    12.  
    13. End Function
    You could generalize the function some more by passing the separator character.

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106
    You can pass arrays just fine, your argument in the sub/function declaration just is myArr() as string instead of myStr as string.

  4. #4

    Thread Starter
    Addicted Member Para80d's Avatar
    Join Date
    Oct 2003
    Location
    Denton, TX
    Posts
    160
    Thanks guys, I ended up doing this

    VB Code:
    1. Function SplitCmdStr(strCmdStr As String) As Variant
    2.  
    3.     If Len(strCmdStr) > 0 And InStr(strCmdStr, "::") > 0 Then
    4.         SplitCmdStr = Split(strCmdStr, "::")
    5.     Else
    6.         SplitCmdStr = Empty
    7.     End If
    8.    
    9. End Function
    Works all good for me!
    C++/VB6&.NET/QBasic/HTML/PHP/MySQL/SQLServer2k

    I'm the guy your little brother looks a lot alike. Tell your mom i said thanks.

    naked in vegas

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Why are you returning a variant? It would be better to return a String array as in my example. Also why set the return value to empty when there's nothing to split? I would think you'd want to return the input.

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