Here is an example:
Code:Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim str As String = "WI - WI - WI - IL - IL" Dim newStr As String = Me.GetStatsString(str) End Sub Private Function GetStatsString(ByVal statesStr As String) As String Dim states() As String = statesStr.Split(New String() {" - "}, StringSplitOptions.RemoveEmptyEntries) Dim stateList As New List(Of String) For Each state As String In states state = state.Trim If Not stateList.Contains(state) Then stateList.Add(state) End If Next Dim newStatesStr As String = String.Empty For i As Integer = 0 To stateList.Count - 1 If i = 0 Then newStatesStr = stateList(i) Else newStatesStr &= " - " & stateList(i) End If Next Return newStatesStr End Function End Class




Reply With Quote