StreamReader如何换行?
using (StreamReader sr = new StreamReader(Server.MapPath( "news ") + "\\sj.html ",System.Text.Encoding.GetEncoding( "GB2312 ")))
{
string str;
//读取指定的HTML文件模板
while ((str = sr.ReadLine()) != null)
{
strhtml.Append(str);
}
sr.Close();
}
---------
strhtml.Append(str);是追加的意思,如何换行追加,用哪个函数?
str=sw.ReadToEnd();不行,生成的是空白
thanks
------解决方案--------------------public string texttohtml(string inputstring)
{
stringbuilder retval = new stringbuilder();
if ((inputstring != null) && (inputstring != string.empty))
{
//inputstring = inputstring.trim();
for (int i = 0; i < inputstring.length; i++)
{
switch (inputstring[i])
{
case ":
retval.append( "" ");
break;
case <:
retval.append( "< ");
break;
case > :
retval.append( "> ");
break;
case :
retval.append( " ");
break;
case (char)13:
retval.append( " <br> ");
break;
case \n:
retval.append( " ");
break;
default:
retval.append(inputstring[i]);
break;
}
}
retval.replace( " ", "’ ");
}
return retval.tostring();
}
------解决方案--------------------mark
------解决方案--------------------strHtml.append( " <br> ");
------解决方案--------------------strhtml.Append(str).Append "\r\n ";
------解决方案--------------------strhtml.Append(str).Append( "\r\n ");