Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# read file by line

using (var file = new StreamReader(fileName)) {
	string line;
	while((line = file.ReadLine()) != null)  
	{  
		System.Console.WriteLine(line);
	}  
}
Comment

c# read file line by line

using System;
using System.IO;
 
public class Example
{
    public static void Main()
    {
        string fileName = @"C:examplepath.txt";
 
        using (StreamReader streamReader = File.OpenText(fileName))
        {
            string text = streamReader.ReadToEnd();
            string[] lines = text.Split(Environment.NewLine);
 
            foreach (string line in lines) {
                Console.WriteLine(line);
            }
        }
    }
}
Comment

how to read particular line of file in c#

string GetLine(string fileName, int line)
{
   using (var sr = new StreamReader(fileName)) {
       for (int i = 1; i < line; i++)
          sr.ReadLine();
       return sr.ReadLine();
   }
}
Comment

c# code to read txt file line by line and split

string lines = File.ReadAllText(path);
string [] split_arr = lines.Split(';')//files containt ; seprated values
  foreach(string l in split_arr)
  {
    Console.WriteLine(l);
  }
Comment

PREVIOUS NEXT
Code Example
Csharp :: string to enum c# 
Csharp :: c# count number of occurrences in string 
Csharp :: write to file c# 
Csharp :: how to input a double in c# 
Csharp :: how to get all files from folder and subfolders in c# 
Csharp :: dotnet dev-certs https --clean 
Csharp :: c# get cpu id 
Csharp :: unity remove gameobject 
Csharp :: random number generator c# 
Csharp :: c# post get request 
Csharp :: unity disable parent gameobject 
Csharp :: move towards target unity 
Csharp :: unity empty action 
Csharp :: OnCollision update unity 
Csharp :: base64 bit string to pdf c# 
Csharp :: c# exit application 
Csharp :: base64decode C# 
Csharp :: sum of digits in c# 
Csharp :: c# start as adminstrator 
Csharp :: change a dropdown to a specific option via script 
Csharp :: how to make a quit button in unity 
Csharp :: c# check if is float 
Csharp :: constraint unity 2d 
Csharp :: generate a random number in c# 
Csharp :: iactionresult 
Csharp :: remove element from sting array c# 
Csharp :: how to destroy an object in unity 
Csharp :: c# read from text documenmt 
Csharp :: newtonsoft json conditionally ignore property 
Csharp :: c# get size of file 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =