asp.net关于长文章的分页问题。

jack15850798154 2010-07-22 10:37:12
现在的问题是关于内容页中的 html 代码。如果实现分页,容易被截断出现问题,请问这个问题如何解决。谢谢各位!
...全文
81 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
jackyzsy2008 2010-07-22
  • 打赏
  • 举报
回复
录入文章数据的时候把页分好
jack15850798154 2010-07-22
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 yan267 的回复:]
引用 13 楼 jack15850798154 的回复:
[Quote=引用 9 楼 yan267 的回复:]
引用 8 楼 jack15850798154 的回复:
各位大哥能给我一个例子参考一下吗? 我不明白各位所说的手动分页是什么意思啊!还请指教一下。谢谢。


手动分页就是在你文章中添加一些标识例如“111111 <#page#>111112”

判断的时候发现<#page……
[/Quote]
你的意思我知道了!谢谢了。
yan267 2010-07-22
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 jack15850798154 的回复:]
[Quote=引用 9 楼 yan267 的回复:]
引用 8 楼 jack15850798154 的回复:
各位大哥能给我一个例子参考一下吗? 我不明白各位所说的手动分页是什么意思啊!还请指教一下。谢谢。


手动分页就是在你文章中添加一些标识例如“111111 <#page#>111112”

判断的时候发现<#page#>就分页。
是不是我在添加文章的时候都要在添加文章的时候……
[/Quote]

晕倒。

你在文章中插入<#page#> 就可以了。
这样111111 是第一页。111112就是第二页啊。

你在编辑框里面添加一个按钮,点击按钮,就在编辑框插入<#page#> 就可以了。
jack15850798154 2010-07-22
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 yan267 的回复:]
引用 8 楼 jack15850798154 的回复:
各位大哥能给我一个例子参考一下吗? 我不明白各位所说的手动分页是什么意思啊!还请指教一下。谢谢。


手动分页就是在你文章中添加一些标识例如“111111 <#page#>111112”

判断的时候发现<#page#>就分页。
是不是我在添加文章的时候都要在添加文章的时候写上 “ 一些标识例如“111111 <#page#>111112” ”啊。
jack15850798154 2010-07-22
  • 打赏
  • 举报
回复
谢谢各位,我研究研究啊,谢谢。
yz_888 2010-07-22
  • 打赏
  • 举报
回复
手动分页好复杂阿 学习~
yan267 2010-07-22
  • 打赏
  • 举报
回复

//content 内容 length 长度 StripHTML 是否除掉HTML来分割
public static string GetContentSummaryEN(string content, int length, bool StripHTML)
{

string NowCheckLength = "";
if (length < content.Length)
{
NowCheckLength = "1";
}




if (string.IsNullOrEmpty(content) || length == 0)
return "";
if (StripHTML)
{
Regex re = new Regex("<[^>]*>");
content = re.Replace(content, "");
content = content.Replace(" ", "").Replace(" ", "");
if (content.Length <= length
)
return content;
else
CheckLeng = "1";
return content.Substring(0, length) + "……";
}
else
{


if (content.Length <= length)
return content;

int pos = 0, npos = 0, size = 0;
bool firststop = false, notr = false, noli = false;


StringBuilder sb = new StringBuilder();

while (true)
{
if (pos >= content.Length)
break;




string cur = content.Substring(pos, 1);


if (cur == "<")
{
string next = content.Substring(pos + 1, 3).ToLower();
if (next.IndexOf("p") == 0 && next.IndexOf("pre") != 0)
{
npos = content.IndexOf(">", pos) + 1;
}
else if (next.IndexOf("/p") == 0 && next.IndexOf("/pr") != 0)
{
npos = content.IndexOf(">", pos) + 1;
if (size < length)
sb.Append("<br/>");
}
else if (next.IndexOf("br") == 0)
{
npos = content.IndexOf(">", pos) + 1;
if (size < length)
sb.Append("<br/>");
}
else if (next.IndexOf("img") == 0)
{
npos = content.IndexOf(">", pos) + 1;
if (size < length)
{
sb.Append(content.Substring(pos, npos - pos));
size += npos - pos + 1;
}
}
else if (next.IndexOf("li") == 0 || next.IndexOf("/li") == 0)
{
npos = content.IndexOf(">", pos) + 1;
if (size < length)
{
sb.Append(content.Substring(pos, npos - pos));
}
else
{
if (!noli && next.IndexOf("/li") == 0)
{
sb.Append(content.Substring(pos, npos - pos));
noli = true;
}
}
}
else if (next.IndexOf("tr") == 0 || next.IndexOf("/tr") == 0)
{
npos = content.IndexOf(">", pos) + 1;
if (size < length)
{
sb.Append(content.Substring(pos, npos - pos));
}
else
{
if (!notr && next.IndexOf("/tr") == 0)
{
sb.Append(content.Substring(pos, npos - pos));
notr = true;
}
}
}
else if (next.IndexOf("td") == 0 || next.IndexOf("/td") == 0)
{
npos = content.IndexOf(">", pos) + 1;
if (size < length)
{
sb.Append(content.Substring(pos, npos - pos));
}
else
{
if (!notr)
{
sb.Append(content.Substring(pos, npos - pos));
}
}
}
else
{
npos = content.IndexOf(">", pos) + 1;
sb.Append(content.Substring(pos, npos - pos));
}
if (npos <= pos)
npos = pos + 1;
pos = npos;
}
else
{





if (size < length)
{
string GetWord = "";
if (ASCIIEncoding.ASCII.GetBytes(cur)[0] > 65 || ASCIIEncoding.ASCII.GetBytes(cur)[0] < 122)
{

bool flag = false;
while (!flag)
{
if (pos >= content.Length)
break;

string str = content.Substring(pos, 1);
GetWord = GetWord + str;
byte a = ASCIIEncoding.ASCII.GetBytes(str)[0];
if (a < 65 || a > 122)
{
flag = true;
}
else
{
pos += 1;
}
}
sb.Append(GetWord);

}
else
{
sb.Append(cur);
}


//sb.Append(cur);
size++;
//sb.Append(cur);
//size++;

}
else
{
if (!firststop)
{
CheckLeng = "1";
//sb.Append("……");
firststop = true;
}
}
pos++;
}

}

string HTML = sb.ToString();
if (NoHTML(HTML).Length != NoHTML(content).Length || CheckLeng == "1")
{
CheckLeng = "1";

HTML = HTML + "……";
}
return HTML;
}
}

public static string NoHTML(string Htmlstring)
{

//删除脚本

Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);

//删除HTML

Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);

Htmlstring.Replace("<", "");

Htmlstring.Replace(">", "");

Htmlstring.Replace("\r\n", "");

Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();

return Htmlstring;

}


以前写的一个保持HTML分割的函数,你自己试试了。
yan267 2010-07-22
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 jack15850798154 的回复:]
各位大哥能给我一个例子参考一下吗? 我不明白各位所说的手动分页是什么意思啊!还请指教一下。谢谢。
[/Quote]

手动分页就是在你文章中添加一些标识例如“111111 <#page#>111112”

判断的时候发现<#page#>就分页。
jack15850798154 2010-07-22
  • 打赏
  • 举报
回复
各位大哥能给我一个例子参考一下吗? 我不明白各位所说的手动分页是什么意思啊!还请指教一下。谢谢。
yan267 2010-07-22
  • 打赏
  • 举报
回复
手动分页是最方便的,如果你要自己分页的话,告诉你一个思路:就是按照标签符和字符来分割,而不是单纯根据字符数,例如"<"开始后一定要到">"结束。

这样才能保证HTML的完整。
journey_q 2010-07-22
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 winner2050 的回复:]
只能是手动分页了。

你看看门户网站有哪个是自动分页的?
[/Quote]

顶~
winner2050 2010-07-22
  • 打赏
  • 举报
回复
只能是手动分页了。

你看看门户网站有哪个是自动分页的?
zengbingling 2010-07-22
  • 打赏
  • 举报
回复
最好是手动分页。在分页处加标签
wuyq11 2010-07-22
  • 打赏
  • 举报
回复
添加分页标识,split
或过滤HTML分页
hyunwung 2010-07-22
  • 打赏
  • 举报
回复
在整个文本中以“\r\n”作为分页标识点。
benimaru10101954 2010-07-22
  • 打赏
  • 举报
回复
手动分页 就没有这个问题了

62,073

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧