Считывание текста из файла - C# (192375)
Формулировка задачи:
как в этом коде изменить так что бы строка не была задана, а считывалась из файла формата txt?
public static void Main()
{
string words = "This is a list of words, with: a bit of punctuation" +
"\tand a tab character.";
string[] split = words.Split(new Char[] { ' ', ',', '.', ':', '!' });
foreach (string s in split)
{
if (s.Trim() != "")
Console.WriteLine(s);
}
}Решение задачи: «Считывание текста из файла»
textual
Листинг программы
string words = "This is a list of words, with: a bit of punctuation" +
"\tand a tab character.";
using (System.IO.StreamReader reader = new System.IO.StreamReader(@"C:\123.txt"))
{
words = reader.ReadToEnd();
}
string[] split = words.Split(new Char[] { ' ', ',', '.', ':', '!' });
foreach (string s in split)
{
if (s.Trim() != "")
Console.WriteLine(s);
}