A Program That Compares The Characters of Two Strings

Sample Code
Public Class StringComparism

    Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
        txtFS.Text = "" : txtSS.Text = "" : lbCommonCharacter.Text = ""
    End Sub

    Private Sub btnCompare_Click(sender As Object, e As EventArgs) Handles btnCompare.Click
        Dim string1 As String = txtFS.Text
        Dim string2 As String = txtSS.Text
        Dim CommonCharacter As String = ""
        Dim NewString As String = String.Empty
        For i = 0 To string1.Length - 1
            If string2.Contains(string1(i).ToString) Then
                NewString &= string1(i).ToString
            End If
        Next
        If NewString = "" Then
            lbCommonCharacter.Text = "NO" : MsgBox("NO")
        Else
            lbCommonCharacter.Text = "YES" : MsgBox("YES")
        End If

End Class

Task
                You are given two strings, A and B.
          Find programmatically if there are common characters that appears in both A              and B.
Display YES (in a newline), if there are common characters.
          Otherwise, display NO.
Constraints: All the strings contain only lowercase Latin letters.

          Example:
hello and world prints YES
                    hi and world prints NO 

Comments

Popular posts from this blog

Nigerian Air Force DSSC 2018 - Information

Facebook Job - Secrets and Tips (Applicants)