简体   繁体   中英

Vb.net two comma separated lists

I am being passed two strings that contain comma separated lists.

string1 (1,2,3,4)
String2 (Red, blue, yellow, purple)

I want to pass each pair to another routine to process them. The strings can change along with the index.

I have to split each string value and loop through both so that I could pass each pair to a subroutine

Use Split to get each component between the commas and pass this:

    Dim string1 As String = "1,2,3,4"
    Dim string2 As String = "Red,blue,yellow,purple"

    Dim string1AsArray = string1.Split(","c)
    Dim string2AsArray = string2.Split(","c)

    For i = 0 To string1AsArray.Count - 1
        MyRoutine(string1AsArray(i), string2AsArray(i))
    Next

you may want to check that both of the arrays are the same size otherwise you may get an exception thrown

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM