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
 

Write, close and dispose string by using “string writer” class in vb and C# .net.

Author: Maliha Atteeq
Download Source Code : 1055_stringApplication.zip

In this simple article you will know how can we write, close and dispose string 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 write in a string:

In order to write in a string, string writer class provides us a function named as write(). This function has 16 overloaded methods. Depending on your requirements you can use any of them. I use the method which takes a character value as an input. The return type of this function is void.

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

C#:

private void btn_write_Click_1(object sender, EventArgs e)

        {

            obj.Write('a');

            MessageBox.Show("string writer writes  "+Convert.ToString(obj));

        }

VB:

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

    obj.Write("a"c)

    MessageBox.Show("string writer writes " & Convert.ToString(obj))

End Sub

To write a line in a string:

In order to write a line in a string, string writer class provides us a function named as writeLine(). This function has 17 overloaded methods. Depending on your requirements you can use any of them. I use the method which takes a string value as an input. It writes the value and a newline. The return type of this function is void.

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

C#:

private void btn_writeLine_Click(object sender, EventArgs e)

        {

            obj.WriteLine("test string");

            MessageBox.Show("string writer writes " + Convert.ToString(obj));

        }

vB:

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

    obj.WriteLine("test string")

    MessageBox.Show("string writer writes " & Convert.ToString(obj))

End Sub

To dispose a string:

In order to dispose a string, string writer class provides us a function named as dispose(). This function takes no argument as a parameter. It free all the resources acquired by the string writer object. The return type of this function is void.

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

C#:

private void btn_dispose_Click(object sender, EventArgs e)

        {

            obj.Dispose();

            MessageBox.Show("all resources acquired by this string writer are set to free");

        }

VB:

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

    obj.Dispose()

    MessageBox.Show("all resources acquired by this string writer are set to free")

End Sub

To close a string:

In order to close a string, string writer class provides us a function named as close(). This function takes no argument as a parameter. It closes the object of the string writer. The return type of this function is void.

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

C#:

private void btn_close_Click(object sender, EventArgs e)

        {

            obj.Close();

            MessageBox.Show("the string writer is set to free");

        }

VB:

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

    obj.Close()

    MessageBox.Show("the string writer is set to free")

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 can we write, close and dispose string by using “string writer” class in vb and C# .net.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Get the absolute path, Uri, authority and fragment associated with Uri using “Uri” class in vb and C# .net.

Disclaimer - Privacy
© 2002-2017 DevASP.net