im trying to split the value using "," and it success but how i want to remove "," symbol at the of my array data
example of my problme
1,2,3,4,5,

expected result
1,2,3,4,5

Just a brief idea...
calculate the length of the array data....check if the last data in the length is , and then try to remove it....

else show some part of ur code...

here what i got

For i = 0 To checkitem1.Items.Count - 1
        If checkitem1.Items.Item(i).Selected = True Then
                    chklistmenu = i.Split(",")
                    For count = 0 To chklistmenu.Length - 1
                        chklistmenu = (chklistmenu(count))
                    Next

         End If
Next

If there is no space after the final comma, setting the RemoveEmptyEntries option should work. Here is an example:

   Dim s As String = "1,2,3,4,5,"
   Dim parts() As String = s.Split(","c)
   Stop
   ' will yield 6 entries

   parts = s.Split(New Char() {","c}, StringSplitOptions.RemoveEmptyEntries)
   Stop
   ' will yield 5 entries

   ' however this senario will yield 6 entries
   s = "1,2,3,4,5, "
   parts = s.Split(New Char() {","c}, StringSplitOptions.RemoveEmptyEntries)
   Stop

Using the example TnTinMN put above if you may get a space after the last comma and don't want the empty entry use trim on the string first.

dim s as String =  trim(MyString)
dim parts() as string = s.split(New Char() {","c} StringSplitOptions.RemoveEmptyEntries)

The following will take any input string and replace it with the longest possible string that starts and ends with a digit.

Imports System.Text.RegularExpressions

    Dim str As String = "1,2,3,4,5,"
    Dim m As Match = Regex.Match(str, "\d.*\d")
    str = m.Value

Edited 4 Years Ago by Reverend Jim

This article has been dead for over six months. Start a new discussion instead.