txt文件中存储多行标题+空格+作者名,现按格式“标题+|+作者”的形式输出,如果标题长度超过10,则将超出的标题部分以"...”形式输出。
static void Main(string[] args)
{string[] lines = System.IO.File.ReadAllLines(@"f:\1.txt", Encoding.Default);
foreach (string line in lines)
{
string[] str = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
string title = str[0];
string author = str[1];
title = title.Substring(0, title.Length > 10 ? 10 : title.Length);
if (title.Length == 10)
{
title = title + "...";
}
Console.WriteLine(title + "|" + author);
}
Console.ReadKey();
}