tags:

views:

164

answers:

2

i have a string that looks like this

"Patient Name, Doc Name, Patient ID, something else"

i want to extract each one of these and put it in a variable. such that var1 will equal "Patient Name" var2 will equal "Doc name" etc.. using instr and mid. what is the best way to do it?

+1  A: 

You should consider using the string methods that are part of the .NET framework instead of the legacy VB functions.

String.Split() will get you 99% of the way to what you want.

Michael Burr
cool how do i use that?
I__
+7  A: 

The best way to do it is using the Split function - here's some vba code to do it:

Dim txt as String = "Patient Name, Doc Name, Patient ID, something else"
Dim x as Variant
Dim i as Long

x = Split(txt, ",")
For i = 0 To UBound(x)
   Debug.Print x(i)
Next i

And in VB.Net:

Dim txt as String = "Patient Name, Doc Name, Patient ID, something else"
Dim split As String() = txt.Split(",")
    For Each s As String In  split
        If s.Trim() <> "" Then
            Console.WriteLine(s)
        End If
    Next s
brendan
+1 for the answer in both... :-)
Buggabill