Live Chat Icon For mobile
Live Chat Icon

How to read specific characters from a text file

Platform: ASP.NET| Category: Files

Use namespace System.IO

VB.NET


Dim fs As New System.IO.FileStream(Server.MapPath('1.txt'), IO.FileMode.Open)
Dim buffer(5) As Byte ’ 5=> number of characters to be read
fs.Read(buffer, 0, 5)
fs.Close()
Dim filechars() As Char = System.Text.Encoding.ASCII.GetChars(buffer)
Dim filestring As String = New String(filechars)
Response.Write(filestring)

C#


FileStream fs =new  FileStream(Server.MapPath('1.txt'),  FileMode.Open);
Byte[] buffer= new byte [5]   ; //5 => Number of characters to be read
fs.Read(buffer, 0, 5);
fs.Close();
Char[]  filechars   = System.Text.Encoding.ASCII.GetChars(buffer);
string filestring   = new String(filechars);
Response.Write(filestring);

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.