Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Dim str As String = ""
        For i As Integer = 0 To CheckBoxList1.Items.Count - 1
            If CheckBoxList1.Items(i).Selected Then
                If str = "" Then
                    str = CheckBoxList1.Items(i).Value
                Else
                    str += "," + CheckBoxList1.Items(i).Value
                End If
            End If
        Next



str has value like="12,13,14,15"
how to split this value and store in arrey?
Posted
Comments
Richard MacCutchan 10-Mar-14 8:01am    
string.Split().

you can use something like this...


VB
Dim str As String = "12,54,125,148,87"

Dim arry As String() = str.TrimEnd(",").Split(",")
 
Share this answer
 
Dim TestArray() As String = Split(str, ",")
 
Share this answer
 
use as below

VB
Dim str As String = ""
        For i As Integer = 0 To CheckBoxList1.Items.Count - 1
            If CheckBoxList1.Items(i).Selected Then
                If str = "" Then
                    str = CheckBoxList1.Items(i).Value
                Else
                    str += "," + CheckBoxList1.Items(i).Value
                End If
            End If
        Next
Dim arry As String() = str.Split(",")

Thanks,
-RG
 
Share this answer
 
just as a litte suggestion
VB
Dim this as String()
this = CheckedListBox1.CheckedItems.Cast(Of String).ToArray

kinda the same as your Code, but gives already back the Array you want.



when you want the Array back to the seperated String..
VB
Dim seperated as String = String.Join(",", this)
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900