how to compare string in vb.net

izza_azhar

Member
Joined
Mar 1, 2006
Messages
17
Programming Experience
Beginner
hye all,
how can i compare string in vb.net

dim output as string = "today if friday"
dim input as string

'for example:
input = Me.txtInput.Text

if input = output ---> i dont know how to do that...
msgbox("correct")
else
msgbox("Incorrect")
end if

thanks~
 
Exactly what you've posted is correct. You simply use the "=" operator to compare two strings. Note that that will use the default behaviour with regard to character casing. You can also use the String.Compare method to force either a case-sensitive or -insensitive comparison.
 
jmcilhinney said:
Exactly what you've posted is correct. You simply use the "=" operator to compare two strings. Note that that will use the default behaviour with regard to character casing. You can also use the String.Compare method to force either a case-sensitive or -insensitive comparison.

i'm really interested to string.compare but dont know how to use it.
i'm gonna use quite long string and i guess this very useful.
can u pls help mer?
thanks~
 
izza if you start a topic on this we might be able to help you if you show some code.

Regards,
Pace
 
The Compare method compares two strings and returns an integer value. The return value of Compare method can be less than zero, greater than zero or equals to zero.
VB.NET:
[COLOR=#0000ff]Dim[/COLOR] str1 [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]String[/COLOR] = "ppp"
[COLOR=#0000ff]Dim[/COLOR] str2 [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]String[/COLOR] = "ccc"
[COLOR=darkgreen]'*declare a new variable that will hold the value *[/COLOR]
[COLOR=#0000ff]Dim[/COLOR] res [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = [COLOR=#0000ff]String[/COLOR].Compare(str1, str2)
MessageBox.Show("First result:" + res.ToString())
str2 = "ttt"
res = [COLOR=#0000ff]String[/COLOR].Compare(str1, str2)
MessageBox.Show("Second result:" + res.ToString())
str1 = "ttt"
res = [COLOR=#0000ff]String[/COLOR].Compare(str1, str2)
MessageBox.Show("Third result:" + res.ToString())

Regards ;)
 
Back
Top