在vb.net中最好地使用MID和INSTR

l--*_*''' 2 .net vb.net

我有一个看起来像这样的字符串

"患者姓名,医生姓名,患者ID,其他内容"

我想提取其中的每一个并将其放在一个变量中.这样var1将等于"患者姓名"var2将等于"Doc name"等...使用instr和mid.最好的方法是什么?

bre*_*dan 7

最好的方法是使用Split函数 - 这里有一些vba代码:

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
Run Code Online (Sandbox Code Playgroud)

在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
Run Code Online (Sandbox Code Playgroud)