searchng a string

If i have a string..say containing "me:You"
How can i use code to divide this string into two string containing the data before the : and the other string containing the data after.

eg original string = me:you
NewString One must = me
NewStringTwo must = you

How can i do this plz?
Who is Participating?
slgalConnect With a Mentor Commented:
   Dim strOrg As String
    Dim str1 As String
    Dim str2 As String
    Dim nPos As Integer
    strOrg = "me:You"
    nPos = InStr(1, strOrg, ":")
    str1 = Mid(strOrg, 1, nPos - 1)
    str2 = Mid(strOrg, nPos + 1)

Hope it helps :>~

If you have VB6, there is an even neater way... The brand new 'Split' function splits a delimited string into an array. Like this:

Sub TryThis()
  Dim txt, arr, i
  txt = "Me:and:you:Mary:and:Peter"
  arr = Split(txt, ":")
  For i = LBound(arr) to Ubound(arr)
    Msgbox arr(i)
  Next i
End Sub

Ture Magnusson
Karlstad, Sweden
vbkannAuthor Commented: i dont have vb6 ..yet but thanks anyway
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.