Monday, 12 March 2012

vb.net string compare()?


How to string compare() in vb.net?
I this tutorial you can learn how to compare two given string (comparison in numbers(integer format)) , syntax for comapare
String.compare(string str,string str2,boolen as integer)
Here : Stràfisrt string
Str2àsecond string
Boolenàtrue or false
String à string data type
Ex: str = string.compare(str1,str2)
To check str1>str2=greater than zero
Str2>str1= less than zero
Str1=str2=zero
  To do this program following steps to be followed
Step1:
Open Microsoft visual studio 2010 or any older version also may differ commands
Step2:
Open file new project(ctrl+shift+n)àselect windows form applicationà rename as you wish
Step3:
Drag and drop two label, textbox, and one button
Label1.textà1st string
Label2.textà2nd string
Buttonàcheck
Step4:
Copy and paste the following code
Public Class Form1
   
    Private SubButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton1.Click
        Dim ststring As String = TextBox1.Text
        Dim ndbstring As String = TextBox2.Text
        Dim result_in_integer AsInteger
        'result_in_integer = String.Compare(TextBox1.Text, TextBox2.Text)
        'MessageBox.Show(result_in_integer)
        result_in_integer = String.Compare(TextBox1.Text, TextBox2.Text, True)
        MessageBox.Show(result_in_integer)


    End Sub
End Class



 Output:


No comments:

Post a Comment