Im Yooki .....
Im doing my project in asp .net with vb coding...
Now i want to compare Two Strings in textbox....
For ex: Thomus .CA and Thomus .CC....Here i have to compare whether the two members r same r not...
Im so new to this site and also new to asp .net...
can one guide me ....
Can anyone give suggestions with a simple example means means it would be great help to do my project....
Thanks in advance....:-/:-/:-/

Dani AI

Generated

As described, the goal is a character-by-character comparison of two TextBox values (for example "Thomus .CA" vs "Thomus .CC"). pointed to the quick built-in equality path and questioned why you would do letter-by-letter. Letter-by-letter is useful when you need the exact mismatch positions (to highlight differences to a user), to normalize messy input first, or when you want a fuzzy / typo-tolerant comparison instead of strict equality.

Practical steps: trim and clean the inputs (remove stray spaces around punctuation in the example), decide whether the check should be case-sensitive, normalize Unicode forms, then walk the strings comparing characters up to the shorter length and record differing indices; if lengths differ record the remaining positions. If you want fuzzy matching (allow small typos) compute a Levenshtein distance and set a threshold. See String.Normalize for Unicode normalization and Levenshtein distance for fuzzy matching theory.

The snippet below shows a compact VB.NET routine that performs letter-by-letter comparison, returns mismatch positions and a short report — adapt the cleaning rules (spaces, punctuation, splitting on ".") to fit whether you compare full strings or parts like username vs TLD.

Function CompareStringsCharByChar(s1 As String, s2 As String, Optional ignoreCase As Boolean = True) As String
    If s1 Is Nothing Then s1 = String.Empty
    If s2 Is Nothing Then s2 = String.Empty
    s1 = s1.Trim()
    s2 = s2.Trim()
    s1 = System.Text.RegularExpressions.Regex.Replace(s1, "\s+\.", ".")
    s2 = System.Text.RegularExpressions.Regex.Replace(s2, "\s+\.", ".")
    If ignoreCase Then
        s1 = s1.ToLowerInvariant()
        s2 = s2.ToLowerInvariant()
    End If
    s1 = s1.Normalize()
    s2 = s2.Normalize()
    Dim minLen = Math.Min(s1.Length, s2.Length)
    Dim diffs As New System.Collections.Generic.List(Of Integer)
    For i As Integer = 0 To minLen - 1
        If s1(i) <> s2(i) Then diffs.Add(i)
    Next
    If s1.Length <> s2.Length Then
        For i As Integer = minLen To Math.Max(s1.Length, s2.Length) - 1
            diffs.Add(i)
        Next
    End If
    If diffs.Count = 0 Then Return "No differences after normalization."
    Return "Differences at: " & String.Join(", ", diffs) & vbCrLf & "Left: " & s1 & vbCrLf & "Right: " & s2
End Function

Use it as Dim report = CompareStringsCharByChar(TextBox1.Text, TextBox2.Text) and show report in a label. For identity checks (user accounts) prefer a stable unique ID rather than display text.

Recommended Answers

All 5 Replies

If (textBox1.Text.Equals(textBox2.Text)) Then
   ' your text is equal
Else 
   ' your text is not equal
End If
If (textBox1.Text.Equals(textBox2.Text)) Then
   ' your text is equal
Else 
   ' your text is not equal
End If

Thanks for ur reply....
I want to know how to compare letter by letter from two u know means can u please guide me with a simple eg....
Thanks in advance:-/

Thanks for ur reply....
I want to know how to compare letter by letter from two u know means can u please guide me with a simple eg....
Thanks in advance:-/

What he's stated is inbuilt string method. When you've something inbuilt then why do you want to compare it letter by letter ??

That was the simple example, for more info check out msdn

What he's stated is inbuilt string method. When you've something inbuilt then why do you want to compare it letter by letter ??

That was the simple example, for more info check out msdn

Thanks I got ur point

If (textBox1.Text.Equals(textBox2.Text)) Then
   ' your text is equal
Else 
   ' your text is not equal
End If

Thanks for ur reply....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.