Splitting a string into separate strings

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jremio
    New Member
    • Oct 2008
    • 2

    Splitting a string into separate strings

    Hey I was wondering how do I go about doing this.

    Code:
    strCommand = readCommand("aaa;sss;ddd", 1)
    MsgBox (strCommand)
    Code:
    Public Function readCommand(str As String, position As Integer) As String
    If position = 1 Then
    	str = Split(str, ";")
    	readCommand = str
    End If
    
    End Function
    I want it such that if the position parameter passed to the readCommand function is 1, the first part of the string "aaa" will be returned, and so on.
    the code above gave a type mismatch, I am guessing its because the Split method is only for arrays? Any suggestions?

    Thanks!
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    Yes, the Split Result Need to Be Assigned to An Array...
    Change your Function Like this :

    Code:
    Public Function readCommand(ByVal Mystr As String, ByVal position As Integer) As String
        Dim TArr
        TArr = Split(Mystr, ";")
        readCommand =""
        '
        On Error Resume Next  ' In Case Position is Out Of Array Range..
        readCommand = TArr(Position-1)
    End Function
    Regards
    Veena

    Comment

    Working...