后台代码:
/// <summary>
/// 将text格式简单的转换成HTML格式保存
/// </summary>
/// <param name="str">进行转换的字符串</param>
/// <returns>转换后的字符串</returns>
public static string ConverToHtml(string str)
{
string tem = str;
tem.Replace(" ", " ");
tem.Replace("<", "<");
tem.Replace(">", ">");
tem .Replace ("\r","<br/>");
tem.Replace("&", "&");
tem .Replace ("/",""");
return tem;
}
这方法很原始,如果行,可以考虑用文本插件。
简单的对文章截取:
/// <summary>
/// 字符段的截取
/// </summary>
/// <param name="str">字符串</param>
/// <param name="length">截取长度</param>
/// <returns>截取后的字符串</returns>
public static string Cut(string str, int length)
{
if (str.Length > length)
{
string stem=null;
for (int i = 0; i < length; i++)
{
stem += str[i];
}
return stem+"……";
}
else
{
return str;
}
}