ADVERTISEMENT
ADVERTISEMENT

VB.Net program to demonstrate StringReader class

Here, we are going to demonstrate StringReader class in VB.Net.
Submitted by Nidhi, on January 06, 2021

Here, we demonstrate the StringReader class, we will read the data line by line using the ReadLine() method of StringReader class.

Program/Source Code:

The source code to demonstrate the StringReader class is given below. The given program is compiled and executed successfully.

'Vb.Net program to demonstrate StringReader class.

Imports System.IO

Module Module1
    Class Sample
        Shared str As String = "This is a cat.
This is dog.
This is elephant."

        Shared Sub ReadLines()
            Dim line As String
            Dim line_num As Integer = 0
            Dim flag As Boolean = True
            Dim strReader As New StringReader(str)

            While (flag = True)
                line = strReader.ReadLine()
                If line = Nothing Then
                    flag = False
                Else
                    line_num = line_num + 1
                    Console.WriteLine("Line {0} : {1}", line_num, line)
                End If
            End While
        End Sub
    End Class

    Sub Main()
        Sample.ReadLines()
    End Sub
End Module

Output:

Line 1 : This is a cat.
Line 2 : This is dog.
Line 3 : This is elephant.
Press any key to continue . . .

Explanation:

In the above program, we created a class module Module1 that contains a class Sample and a Main() function. The Sample class contains a data member str that contains multiple lines of data. It also contains a shared method ReadLine().

In the ReadLines() method, we read the data line by line from data member str using the ReadLine() method of StringReader class and print on the console screen.

The Main() method is the entry point of the program, here we called the shared method ReadLines().

VB.Net StringReader, StringWriter, Stream Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.