16,717
社区成员
发帖
与我相关
我的任务
分享
public static void Output(string fileName) //这里传入文件的名称,带路径
{
if(File.Exist(fileName)) //检查指定位置是否存在相应文件
{
using(StreamReader sr =File.OpenText(fileName)) //打开文件,
{
bool firstLine=false;
do
{
string currentLine = sr.ReadLine(); //读取出一行。
if(currentLine==null)break; //如果到达文件尾则返回NULL,退出循环
if(firstLine)
Console.WriteLine(ConvertHeadString(currentLine.Length); //根据第一行的数据输出头部的ABCD...
Console.WriteLine(ConvertString(currentLine)); //输出每行数字对应的符号
}while(true);
}
}
}
public static string ConvertHeadString(int len) //转换出标题行
{
string ret="";
for(int i=0;i<len;i++)
{
ret +=(new string((char)(i+ 65), 1); //生成一个字符的字符串。根据ASCII码
}
return ret;
}
public static string ConvertString(string sr) //转换出数据行
{
string ret="";
for(int i=0;i<sr.Length;i++)
{
//这里的转换规则不能处理全角的,如果是全角的,你再多加几个case就可以。
switch(sr[i])
{
case '1':
ret+="│";
break;
case '2':
ret +="├";
break;
case '3':
ret +="┤";
break;
}
}
return ret;
}
public static void Output(string fileName)
{
if(File.Exist(fileName))
{
using(StreamReader sr =File.OpenText(fileName))
{
bool firstLine=false;
do
{
string currentLine = sr.ReadLine();
if(currentLine==null)break;
if(firstLine)
Console.WriteLine(ConvertHeadString(currentLine.Length);
Console.WriteLine(ConvertString(currentLine));
}while(true);
}
}
}
public static string ConvertHeadString(int len)
{
string ret="";
for(int i=0;i<len;i++)
{
ret +=(new string((char)(i+ 65), 1);
}
return ret;
}
public static string ConvertString(string sr)
{
string ret="";
for(int i=0;i<sr.Length;i++)
{
switch(sr[i])
{
case '1':
ret+="│";
break;
case '2':
ret +="├";
break;
case '3':
ret +="┤";
break;
}
}
return ret;
}