Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Create - get culture - ordinal - invariant culture of string comparer using string comparer class vb.net - C# .net.

Author: Maliha Atteeq
Download Source Code : 1006_stringComparer.zip

In this simple article you will learn that how to create, get culture,ordinal, invariant culture of string comparer using string comparer class in vb and C# .net.

 String comparer:

String comparer compares two specified String objects. A parameter specifies whether the comparison uses the current or invariant culture, honors or ignores case, and uses word or ordinal sort rules. The method returns an integer that indicates the relationship of the two String objects to one another in the sorted order.

Creation:

In order to create the object of String comparer, string comparer class provides us one static function named as create().The function takes two argument as a parameter, one is the culture information of type cultureInfo and second is the flag for ignoring case. This object compares the string by using the defined culture.

To demonstrate make a new window application. Drag one button on from.

Now write the following code on Button click event:

C#:

private void btn_build_Click(object sender, EventArgs e)

        {

            Boolean ob = true;

            System.Globalization.CultureInfo culture=new System.Globalization.CultureInfo(1);

            StringComparer.Create(culture,ob);

            MessageBox.Show("string comparer creates an object with default operating system culture");

 

        }

VB:

Private Sub btn_build_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim ob As [Boolean] = True

        Dim culture As New System.Globalization.CultureInfo(1)

        StringComparer.Create(culture, ob)

        MessageBox.Show("string comparer creates an object with default operating system culture")

    End Sub

 

 

 

Get current culture:

In order to get the current culture of the string comparer, string comparer class provides us a property named as currentculture. This property returns the culture and the return type of this property is string comparer that is it returns the object of string comparer class.

To demonstrate make a new window application. Drag one button on from.

Now write the following code on Button click event:

C#:

private void btn_getCulture_Click(object sender, EventArgs e)

        {

            StringComparer obj;

            obj=StringComparer.CurrentCulture;

            MessageBox.Show("the current culture is "+Convert.ToString(obj));

        }

VB:

Private Sub btn_getCulture_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim obj As StringComparer

        obj = StringComparer.CurrentCulture

        MessageBox.Show("the current culture is " & Convert.ToString(obj))

    End Sub

Get Ordinal:

In order to perform the case sensitive ordinal string comparison, string comparer class provides us a property named as ordinal. This property returns the ordinal and the return type of this property is string comparer that is it returns the object of string comparer class.

To demonstrate make a new window application. Drag one button on from.

Now write the following code on Button click event:

C#:

private void btn_getOrdinal_Click(object sender, EventArgs e)

        {

            StringComparer obj;

            obj = StringComparer.Ordinal;

            MessageBox.Show("the ordinal is " + Convert.ToString(obj));

         }

VB:

Private Sub btn_getOrdinal_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim obj As StringComparer

        obj = StringComparer.Ordinal

        MessageBox.Show("the ordinal is " & Convert.ToString(obj))

    End Sub

Get Ordinal:

In order toperform the case sensitive string comparison by using the word comparison rule of the invariant culture, string comparer class provides us a property named as InvariantCulture. This property returns the invariant culture and the return type of this property is string comparer that is it returns the object of string comparer class.

To demonstrate make a new window application. Drag one button on from.

Now write the following code on Button click event:

C#:

private void button1_Click(object sender, EventArgs e)

        {

            StringComparer ob;

            ob = StringComparer.InvariantCulture;

            MessageBox.Show("the invariant culture is " + Convert.ToString(ob));

        }

VB:

Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim ob As StringComparer

        ob = StringComparer.InvariantCulture

        MessageBox.Show("the invariant culture is " & Convert.ToString(ob))

    End Sub

Now write the following code on FORM LOAD event:

C#:

private void Form1_Load(object sender, EventArgs e)

        {

            this.Text = "DEVASP STRING COMPARER APPLICATION";

        }

 

Vb:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)

        Me.Text = "DEVASP STRING COMPARER APPLICATION"

    End Sub

This simple article tells that how to create, get culture,ordinal, invariant culture of string comparer using string comparer class in vb and C# .net.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Convert char – double – int and single to byte array using BitConverter class - VB.net - C# .net.

Disclaimer - Privacy
© 2002-2017 DevASP.net