locked
compare two coma seperted string in vb.net RRS feed

  • Question

  • User-651692633 posted

    I have two strings with coma separated values ..

    String-1 is from DB and string -2 is user input.. If string-2 misses any value which was there in string-1 then I need to display a warning.. how do I achieve this

    Tuesday, December 22, 2015 1:11 AM

Answers

  • User1724605321 posted

    Hi anupamabr,

    If string-2 misses any value which was there in string-1 then I need to display a warning

    You could try to use Except Method , Code below is for your reference:

            Dim string1() As String = {"A", "B", "C"}
            Dim string2() As String = {"A", "B"}
    
            ' Select the elements from the first array that are not
            ' in the second array.
            Dim onlyInFirstSet As IEnumerable(Of String) = string1.Except(string2)
            Dim output As New System.Text.StringBuilder
            For Each differ As String In onlyInFirstSet
                output.AppendLine(differ)
            Next
    
            ' Display the output.
            MsgBox(output.ToString())

    It will output "C" which is not in second string .

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 22, 2015 6:02 AM