none
Remove same string RRS feed

  • Question

  • Hi All,

    I have 3 digits number in List "Vito".I want to remove every 3 digits number having the same digit then let One in the list only.

    Option Strict On
    Option Explicit On
    Option Infer Off
    
    Imports System.IO
    Imports System.Data
    Imports System.Windows.Forms
    
    Public Class Form1
    
        Private Vito As New List(Of String)
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Vito.Add("123")
            Vito.Add("230")
            Vito.Add("485")
            Vito.Add("154")
            Vito.Add("123")
            Vito.Add("230")
            Vito.Add("785")
            Vito.Add("621")
    
        End Sub
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    
            For Each Digit As String In Vito
                TextBox1.Text &= Digit & vbCrLf
            Next
    
        End Sub
    
        Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    
        End Sub
    
    End Class

    Expected Result is;

      Vito.Add("230")
     Vito.Add("485")
     Vito.Add("154")
     Vito.Add("123")
     Vito.Add("785")
     Vito.Add("621")

    Thank.


    • Edited by mipakteh Thursday, May 10, 2018 11:30 AM add
    Thursday, May 10, 2018 11:27 AM

Answers

  •     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Vito = Vito.Distinct().ToList
            For Each Digit As String In Vito
                TextBox1.Text &= Digit & vbCrLf
            Next
    
        End Sub

    Thursday, May 10, 2018 11:47 AM
  • Hi mipakteh,

    You can also do like this:

      Private Vito As New List(Of String)
        Dim newList As New List(Of String)()
    
        Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
            Vito.Add("123")
            Vito.Add("230")
            Vito.Add("485")
            Vito.Add("154")
            Vito.Add("123")
            Vito.Add("230")
            Vito.Add("785")
            Vito.Add("621")
    
            For Each s As String In Vito
                If Not newList.Contains(s) Then
                    newList.Add(s)
                End If
            Next
            Vito = newList
    
    
        End Sub

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by mipakteh Friday, May 11, 2018 3:57 AM
    Friday, May 11, 2018 3:02 AM
    Moderator

All replies

  •     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Vito = Vito.Distinct().ToList
            For Each Digit As String In Vito
                TextBox1.Text &= Digit & vbCrLf
            Next
    
        End Sub

    Thursday, May 10, 2018 11:47 AM
  • Hi mipakteh,

    You can also do like this:

      Private Vito As New List(Of String)
        Dim newList As New List(Of String)()
    
        Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
            Vito.Add("123")
            Vito.Add("230")
            Vito.Add("485")
            Vito.Add("154")
            Vito.Add("123")
            Vito.Add("230")
            Vito.Add("785")
            Vito.Add("621")
    
            For Each s As String In Vito
                If Not newList.Contains(s) Then
                    newList.Add(s)
                End If
            Next
            Vito = newList
    
    
        End Sub

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by mipakteh Friday, May 11, 2018 3:57 AM
    Friday, May 11, 2018 3:02 AM
    Moderator