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
 

Get encoding, format provider, life time service by using “string writer” class in vb and C# .net.

Author: Maliha Atteeq
Download Source Code : 1057_stringAppz.zip

In this simple article you will know how we can get encoding, format provider, life time service by using “string writer” class in vb and C #.net.

 String writer:

It implements a TextWriter for writing information to a string. The information is stored in an underlying StringBuilder.

To get encoding:

In order to get encoding of the object of the string writer, this class provides us a property named as Encoding. The return type of this property is the object of encoding. It returns the encoding scheme of the string writer object.

To demonstrate make a new window application. Drag one button on the form and write the following code:

C#:

private void btn_getEncod_Click(object sender, EventArgs e)

        {

            Encoding encod;

            encod=obj.Encoding;

            MessageBox.Show("the encoding scheme is "+Convert.ToString(encod));

        }

 

VB:

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

    Dim encod As Encoding

    encod = obj.Encoding

    MessageBox.Show("the encoding scheme is " & Convert.ToString(encod))

End Sub

To get format provider:

In order to get format provider of the object of the string writer, this class provides us a property named as FormatProvider. The return type of this property is the object of IFormatProvider. It returns the format of the string writer object.

To demonstrate make a new window application. Drag one button on the form and write the following code:

C#:

private void btn_getFormat_Click(object sender, EventArgs e)

        {

            IFormatProvider ob;

            ob=obj.FormatProvider;

            MessageBox.Show("the format provider is " + Convert.ToString(ob));

        }

VB:

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

    Dim ob As IFormatProvider

    ob = obj.FormatProvider

    MessageBox.Show("the format provider is " & Convert.ToString(ob))

End Sub

To get life time service:

In order to initialize the life time service of the object of the string writer, this class provides us a function named as InitializeLifetimeService(). The return type of this property is the object of class object. This function takes no argument as a parameter.

To demonstrate make a new window application. Drag one button on the form and write the following code:

C#:

private void button4_Click(object sender, EventArgs e)

        {

            object ob;

            ob=obj.InitializeLifetimeService();

            MessageBox.Show("the life time service of the object is " + Convert.ToString(ob));

        }

VB:

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

    Dim ob As Object

    ob = obj.InitializeLifetimeService()

    MessageBox.Show("the life time service of the object is " & Convert.ToString(ob))

End Sub

To get life time service:

In order to flush out all the buffers associated with the object of string writer class, this class provides us a function named as Flush(). The return type of this property is void and it takes no argument as a parameter.

To demonstrate make a new window application. Drag one button on the form and write the following code:

C#:

private void btn_flush_Click(object sender, EventArgs e)

        {

            obj.Flush();

            MessageBox.Show("all the buffers are clreared");

        }

VB:

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

    obj.Flush()

    MessageBox.Show("all the buffers are clreared")

End Sub

Now write the following code on FORM LOAD event:

C#:

private void Form1_Load(object sender, EventArgs e)

        {

            this.Text = "DEVASP STRING APPLICATION";

        }

VB:

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

   Me.Text = "DEVASP STRING APPLICATION"

End Sub

This simple article tells how we can get encoding, format provider, life time service by using “string writer” class in vb and C #.net.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Get length, string and substring of a string by using “stringInfo” class in vb and C# .net.

Disclaimer - Privacy
© 2002-2017 DevASP.net