本文整理汇总了C#中StreamReader.ReadLine方法的典型用法代码示例。如果您正苦于以下问题:C# StreamReader.ReadLine方法的具体用法?C# StreamReader.ReadLine怎么用?C# StreamReader.ReadLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StreamReader
的用法示例。
在下文中一共展示了StreamReader.ReadLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
StreamReader reader = new StreamReader("..\\..\\TextInput.txt");
int length = int.Parse(reader.ReadLine());
var matrix = new int[length, length];
using (reader)
{
for (int j = 0; j < length; j++)
{
string currentLine = reader.ReadLine();
string[] line = currentLine.Split(' ');
for (int i = 0; i < length; i++)
{
matrix[j, i] = int.Parse(line[i]);
}
}
}
int sum = int.MinValue;
for (int i = 0; i < length - 1; i++)
{
for (int j = 0; j < length - 1; j++)
{
int localsum = matrix[j, i] + matrix[j, i + 1] + matrix[j + 1, i] + matrix[j + 1, i + 1];
if (sum < localsum)
{
sum = localsum;
}
}
}
Console.WriteLine("The maximum sum of the elements is {0}",sum);
}
示例2: Main
static void Main()
{
try
{
//files are in 'bin/Debug' directory of the project
string allLines = String.Join(" ", File.ReadAllLines("secondfile.txt"));
string[] allWords = allLines.Split(' ');
using (StreamReader start = new StreamReader("mainfile.txt"))
{
string line = start.ReadLine();
using (StreamWriter finish = new StreamWriter("finish.txt"))
{
while (line != null)
{
for (int i = 0; i < allWords.Length; i++)
{
string word = "\\b" + allWords[i] + "\\b";
line = Regex.Replace(line, word, "");
}
finish.WriteLine(line);
line = start.ReadLine();
}
}
}
}
catch (Exception e)
{
Console.WriteLine("{0}:{1}", e.GetType().Name, e.Message);
}
Console.WriteLine("Deleting duplicated words was succesful.");
}
示例3: Main
static void Main()
{
var readerOne = new StreamReader("test.txt", Encoding.GetEncoding("Windows-1251"));
var readerTwo = new StreamReader("test2.txt", Encoding.GetEncoding("Windows-1251"));
using (readerOne)
{
int sameCount = 0;
int differentCount = 0;
string lineOne = readerOne.ReadLine();
using (readerTwo)
{
string lineTwo = readerTwo.ReadLine();
while (lineOne != null)
{
if (lineOne == lineTwo)
{
sameCount++;
}
else
{
differentCount++;
}
lineOne = readerOne.ReadLine();
lineTwo = readerTwo.ReadLine();
}
Console.WriteLine("The same lines are {0} and the different lines are {1}",sameCount,differentCount);
}
}
}
示例4: Main
static void Main()
{
Console.WriteLine("Enter the full path of the text file");
string path = Console.ReadLine();
StreamReader reader = new StreamReader(path);
StreamWriter writer = new StreamWriter("text.txt", false, Encoding.GetEncoding("windows-1251"));
List<string> list = new List<string>();
using (writer)
{
using(reader)
{
string line = reader.ReadLine();
while(line!=null)
{
list.Add(line);
line = reader.ReadLine();
}
list.Sort();
}
foreach (string s in list)
{
writer.WriteLine(s);
}
}
}
示例5: Main
static void Main()
{
StreamReader reader = new StreamReader("../../text.txt", Encoding.GetEncoding("UTF-8"));
StreamWriter writer = new StreamWriter("../../temp.txt", false, Encoding.GetEncoding("UTF-8"));
using (reader)
{
using (writer)
{
string line = reader.ReadLine();
while (line != null)
{
line = Regex.Replace(line, @"\b(test)\w*\b", "");
writer.WriteLine(line);
line = reader.ReadLine();
}
}
}
File.Delete("../../text.txt");
File.Move("../../temp.txt", "../../text.txt");
Console.WriteLine("File \"text.txt\" modified!");
}
示例6: SameWordsSequences
public static Dictionary<string, int> SameWordsSequences(List<string> words)
{
using (StreamReader InputFileTest = new StreamReader("..//..//InputFileTest.txt"))
{
Dictionary<string, int> dictionary = new Dictionary<string, int>();
string line = InputFileTest.ReadLine();
while (line != null)
{
string[] wordsOnLine = line.ToLower().Split(' ', '.', ';', ':');
foreach (string word in wordsOnLine)
{
if (words.Contains(word))
{
if (!dictionary.ContainsKey(word))
{
dictionary.Add(word, 1);
}
else ++dictionary[word];
}
}
line = InputFileTest.ReadLine();
}
return dictionary;
}
}
示例7: Main
static void Main()
{
StreamReader reader = new StreamReader(@"..\..\input.txt");
List<string> allEvenLines = new List<string>();
string currLine = null;
while (1 == 1)
{
currLine = reader.ReadLine();//Line1 (1/3/5/7)
currLine = reader.ReadLine();//Line2 (4/6/8/10)
if (currLine == null)
{
break;
}
allEvenLines.Add(currLine);
}
reader.Close();
StreamWriter writer = new StreamWriter(@"..\..\input.txt", false); // after closing the reader
foreach (string line in allEvenLines)
{
writer.WriteLine(line);
}
writer.Close();
}
示例8: Main
static void Main()
{
StreamReader readerOne = new StreamReader("02.FileOne.txt",Encoding.GetEncoding("UTF-8"));
StreamReader readerTwo = new StreamReader("02.FileTwo.txt", Encoding.GetEncoding("UTF-8"));
// Read first one and write it in the third one
using (readerOne)
{
StreamWriter writeOne = new StreamWriter("02.Concatenation.txt", false, Encoding.GetEncoding("UTF-8"));
using (writeOne)
{
string line = readerOne.ReadLine();
while (line != null)
{
writeOne.WriteLine(line);
line = readerOne.ReadLine();
}
}
}
// Read second one and add it to third one where first one is already overwrited
using (readerTwo)
{
StreamWriter writeTwo = new StreamWriter("02.Concatenation.txt", true, Encoding.GetEncoding("UTF-8"));
using (writeTwo)
{
string line = readerTwo.ReadLine();
while (line != null)
{
writeTwo.WriteLine(line);
line = readerTwo.ReadLine();
}
}
}
}
示例9: Main
static void Main()
{
string fileName = @"..\..\news.txt";
string output = "resulted.txt";
using (StreamWriter writeLines = new StreamWriter(output))
{
using (StreamReader streamReader = new StreamReader(fileName))
{
int lineNumber = 0;
string line = streamReader.ReadLine();
while (line != null)
{
lineNumber++;
writeLines.WriteLine("Line {0}: {1}", lineNumber, line);
line = streamReader.ReadLine();
}
}
}
Console.WriteLine("The Result File can be found at \n02.03.LineNumbers\\bin\\Debug");
}
示例10: Main
static void Main()
{
StreamReader wordsReader = new StreamReader("../../words.txt");
StreamReader textReader = new StreamReader("../../text.txt");
StreamWriter resultWriter = new StreamWriter("../../result.txt");
using (wordsReader)
{
using (textReader)
{
using (resultWriter)
{
List<string> words = new List<string>();
string line = wordsReader.ReadLine();
while (line != null)
{
words.Add(line);
line = wordsReader.ReadLine();
}
List<int> wordsCount = new List<int>();
List<string> text = new List<string>();
line = textReader.ReadLine();
while (line != null)
{
text.Add(line);
line = textReader.ReadLine();
}
for (int i = 0; i < words.Count; i++)
{
wordsCount.Add(0);
for (int j = 0; j < text.Count; j++)
{
if (text[j].ToLower().Contains(words[i].ToLower()))
{
wordsCount[i]++;
}
}
}
Dictionary<string, int> dict = new Dictionary<string, int>();
for (int i = 0; i < words.Count; i++)
{
dict[words[i]] = wordsCount[i];
}
var ordered = dict.OrderByDescending(x => x.Value);
foreach (var item in ordered)
{
resultWriter.WriteLine("{0} - {1}", item.Key, item.Value);
}
}
}
}
}
示例11: Main
static void Main()
{
var text = new StreamReader(@"..\..\Files\text.txt");
var text2 = new StreamReader(@"..\..\Files\text2.txt");
var write = new StreamWriter(@"..\..\Files\concetenate.txt");
string curentLine = "";
using (write)
{
using (text)
{
curentLine = text.ReadLine();
while (curentLine != null)
{
write.WriteLine(text.ReadLine());
curentLine = text.ReadLine();
}
}
write.WriteLine();
using (text2)
{
curentLine = text2.ReadLine();
while (curentLine != null)
{
write.WriteLine(text2.ReadLine());
curentLine = text2.ReadLine();
}
}
}
Console.WriteLine("Complete Work!!!");
Console.ReadLine();
}
示例12: Main
static void Main()
{
StreamReader file1 = new StreamReader(@"..\..\Files\alph.txt");
StreamReader file2 = new StreamReader(@"..\..\Files\newText.txt");
int equalLines = 0;
int diffLines = 0;
using (file1)
{
using (file2)
{
string textToCompare = file1.ReadLine();
string secondText = file2.ReadLine();
while (textToCompare != null)
{
if (textToCompare == secondText)
{
equalLines++;
}
else
{
diffLines++;
}
textToCompare = file1.ReadLine();
secondText = file2.ReadLine();
}
}
}
Console.WriteLine("Equal lines - {0}, and different are - {1}.", equalLines, diffLines);
}
示例13: Main
static void Main()
{
StreamReader reader = new StreamReader(@"..\..\input.txt");
StreamWriter writer = new StreamWriter(@"..\..\ouput.txt");
using (writer)
{
using (reader)
{
int n = int.Parse(reader.ReadLine());
int[,] matrix = new int[n, n];
for (int i = 0; i < n; i++)
{
int[] lineNums = reader.ReadLine()
.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
.Select(x => int.Parse(x))
.ToArray();
for (int j = 0; j < n; j++)
{
matrix[i, j] = lineNums[j];
}
}
writer.WriteLine(maxAreaSum(matrix));
}
}
Console.WriteLine("ready");
}
示例14: Main
static void Main()
{
StreamReader readerOne = new StreamReader(@"..\..\fileOne.txt");
StreamReader readerTwo = new StreamReader(@"..\..\fileTwo.txt");
using (readerOne)
{
using (readerTwo)
{
string linesTextOne = readerOne.ReadLine();
string linesTextTwo = readerTwo.ReadLine();
int count = 1;
List<int> sameLines = new List<int>();
List<int> differentLines = new List<int>();
while (linesTextOne != null)
{
if (linesTextOne.Equals(linesTextTwo))
{
sameLines.Add(count);
}
else
{
differentLines.Add(count);
}
count++;
linesTextOne = readerOne.ReadLine();
linesTextTwo = readerTwo.ReadLine();
}
Console.WriteLine("Same lines: {0}", string.Join(" ", sameLines));
Console.WriteLine("Different lines: {0}", string.Join(" ", differentLines));
}
}
}
示例15: Main
static void Main()
{
StreamReader text1 = new StreamReader("text1.txt", Encoding.GetEncoding("windows-1251"));
StreamReader text2 = new StreamReader("text2.txt", Encoding.GetEncoding("windows-1251"));
using (text1)
{
int lineNumber = 1;
string lineFirstFile = text1.ReadLine();
Console.WriteLine("The text line are:");
Console.WriteLine();
while (lineFirstFile != null)
{
string lineSecondFile = text2.ReadLine();
int result = string.Compare(lineFirstFile, lineSecondFile, true);
if (result==0)
{
Console.Write("equal at: ");
Console.WriteLine(" {0} line ", lineNumber);
}
else
{
Console.Write("not equal at:");
Console.WriteLine(" {0} line", lineNumber);
}
lineNumber++;
lineFirstFile = text1.ReadLine();
}
}
}