Pergunta

For example, I'm having a two set of vars with data type of string:

 users = "Admin, Staff"
 pass = "202cb9, caf1a"

These are vars with only normal string data type. The two vars above is generated, so I could only get these kind of data. The question is: How can I separate those data by the commas (like Admin -> 202cb9, Staff -> caf1a) and then store them into an array.

users_array(0) = "Admin"
users_array(1) = "Staff"
pass_array(0) = "202cb9"
pass_array(1) = "caf1a"

Thank you.

Foi útil?

Solução 2

I have two options to solve this problem:

    Dim users_array() As String = users.Split(New String() {", "}, StringSplitOptions.RemoveEmptyEntries)

and:

    Dim pass_array() As String = Split(users, ", ")

IMO, it is better to use ,<space> as a separator string instead of just ,, to avoid getting <space>staff at index 1.

Here the first solution works for both C# and VB.Net and second one is specific to VB.Net.

Outras dicas

You can use users.Split(New Char() {","c}) as in this link.

http://www.dotnetperls.com/split-vbnet

User String.Split to break strings apart on a specific character. It returns an array.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top