I am in need to convert as below.
Source string :
1,2,6,2-5,10-15
Destination String :
;1;2;6;3;4;5;10;11;12;13;14;15;
in destination string, duplicates not allowed.
Any help appreciated..:thumb:
Printable View
I am in need to convert as below.
Source string :
1,2,6,2-5,10-15
Destination String :
;1;2;6;3;4;5;10;11;12;13;14;15;
in destination string, duplicates not allowed.
Any help appreciated..:thumb:
1. Use String.Split to split the original string on the commas.
2. Create an empty List to store the values.
3. For each element in the split array, split it on the dash.
4. If there's only one element there was no dash. You can just test the List and, if the value isn't present, add it.
5. If there are two elements then there was a dash so you can loop from the first value to the second value.
6. For each value you can, again, test the List and add the value.
Thanks jmc for the steps...
this working fine..Code:Private Function GetSemiColonSeperatedValue(ByVal sCommaSeperatedValue As String) As String
Dim sOutString As String = ";"
Try
For Each sTempComma As String In sCommaSeperatedValue.Split(New Char() {","c}, StringSplitOptions.RemoveEmptyEntries)
If sTempComma.Contains("-") Then
Dim sArr() As String = sTempComma.Split(New Char() {"-"c}, StringSplitOptions.RemoveEmptyEntries)
Dim iMinRange As Integer = Integer.Parse(sArr(0))
Dim iMaxRange As Integer = Integer.Parse(sArr(1))
If iMinRange <= iMaxRange Then
For iTemp As Integer = iMinRange To iMaxRange
If sOutString.Contains(";" & iTemp & ";") = False Then
sOutString &= iTemp & ";"
End If
Next
End If
Else
If sOutString.Contains(";" & sTempComma & ";") = False Then
sOutString &= sTempComma & ";"
End If
End If
Next
Catch ex As Exception
Return String.Empty
End Try
Return sOutString
End Function
:thumb::thumb: