SPlit on a sequence of chars

Ola,

How do I split this string into an array of 2 elements?
"Part1:*-*:Part2".Split(":*-*:".ToCharArray())

This does not seem to work for me

LVL 2
DaFouAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

haikleCommented:
try
Dim ToCharArray as array

ToCharArray = Split ("Part1:*-*:Part2", ":*-*:", , CompareMethod.text)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
grayeCommented:
There isn't a built-in function for a "token" split... so you'll have to write one!

Here is a good starting point... you might consider adding a bit of error checking, etc

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim i As Integer
        Dim parts() As String

        parts = TokenSplit("Part1:*-*:Part2", ":*-*:")
        For i = 0 To UBound(parts)
            Debug.WriteLine(i & ", " & parts(i))
        Next
    End Sub

    Function TokenSplit(ByVal str As String, ByVal token As String) As String()
        Dim ans(10) As String
        Dim ans_count, t_len, marker, prev As Integer

        t_len = token.Length

        ans_count = 0
        prev = 0
        marker = 0
        Do While marker >= 0
            ' find the index for the start of the token
            marker = str.IndexOf(token, marker)
            If marker > 0 Then
                ' copy the substring into our answer array
                ans(ans_count) = str.Substring(prev, marker - prev)
                ans_count += 1
                ' redim in chunks of 10
                If ans_count > UBound(ans) Then
                    ReDim Preserve ans(UBound(ans) + 10)
                End If
                prev = marker
                marker += t_len
            End If
        Loop

        ' don't forget the stuff past the last token
        If prev + t_len < str.Length Then
            ans(ans_count) = str.Substring(prev + t_len)
            ans_count += 1
        End If

        ' special conditions (no token at all)
        If ans_count = 0 Then
            ans_count = 1
            ans(0) = str
        End If

        ReDim Preserve ans(ans_count - 1)
        Return ans
    End Function
DaFouAuthor Commented:
grave, it looks like hailkle's suggestion does the trick just fine
grayeCommented:
Humph... you're right.   The documentation says "a single character" as the delimiter, but obviously a multi-character string works too
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.