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
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
This will trim a trailing comma from a string
If str.EndsWith(",") Then str = str.Substring(0, Len(str) - 1)
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
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.