public string turn(String str)
{
//str 从数据库里取得的数据
while(str.IndexOf("\n")!=-1)
{
str = str.Substring(0,str.IndexOf("\n"))+"<br>"+str.Substring(str.IndexOf("\n")+1);
}
while(str.IndexOf(" ")!=-1)
{
str = str.Substring(0,str.IndexOf(" "))+" "+str.Substring(str.IndexOf(" ")+1);
}
return str;
}
本文介绍了一种将字符串中的换行符和空格转换为HTML格式的方法,通过使用C#的Substring和IndexOf方法,实现将文本数据适配网页显示的需求。
6555

被折叠的 条评论
为什么被折叠?



