Pregunta

I was looking if anyone could help me out on writing this simple code. I would like to make it where I have 2 text boxes and one button. In one of the text boxes I would be inputting a sentence. The second text box I would be inputting the same sentence but a little modified where it would have a miss spelling in one of the words. When I hit the verify button it would check both of the text boxes to see if each of the sentences entered are the same. If they are the same then I would get a message "Same". If they are different then I would get a message "different" and it would display where the error is in the sentence by changing the word in red or something like that.

¿Fue útil?

Solución

for VB that would be:

If firstTB.Text.Equals(secondTB.Text) Then
     lblResult.Text = "Same"
     lblResult.ForeColor = System.Colors.WindowText
Else
     lblResult.Text = "Not the Same"
     lblResult.ForeColor = Color.Red
End If

If you want to compare case insensitive then

If firstTB.Text.ToLowerInvariant = secondTB.Text.ToLowerInvariant Then
    ' etc

One flaw is that you assume one of them is correct. Since the control one (the correct spelling) is in a textbox, the user could edit it before clicking a button. So, either use a label or be sure to set the control on to ReadOnly = True

Otros consejos

In c# you can use.

if(<idtextbox1>.text.equals(<idtextbox2>.text)
{
 <idlabel>.text="Same";
}
else
{
<idlabel>.text="different";

}

Not sure on how to mark the word red, but I'll search a bit and let you know.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top