Long article pagination

Source: Internet
Author: User

For long articles, you must display them by page. In. net generally has two paging methods for long articles. The first method is to calculate the length of the text on a page first, and then divide the total length of the article into the length and availability of the set single-page text, using this method can reduce the complexity of paging, but it may not be correct because it cannot achieve paging in certain characteristic locations. The second is implemented by humans and programs. When a person adds a news item, enter the specified pagination symbol (such as $, which is not common in the article) where the page is to be paged ), then, the program paging through the specified paging symbol, so that you can achieve the paging where you want. This article also uses the second method. The following is a C # code snippet: <br/> Public String nohtml (string htmlstring) // remove the HTML tag <br/>{< br/> // Delete the script <br/> htmlstring = RegEx. replace (htmlstring, @ "<MCE: script [^> <! -- <Br/>] *?>. *? <Br/> // --> </MCE: SCRIPT> "," ", regexoptions. ignorecase); <br/> // delete HTML <br/> htmlstring = RegEx. replace (htmlstring, @ "<(. [^>] *)> "," ", regexoptions. ignorecase); <br/> htmlstring = RegEx. replace (htmlstring, @ "([/R/n]) [/S] +", "", regexoptions. ignorecase); <br/> htmlstring = RegEx. replace (htmlstring, @ "-->", "", regexoptions. ignorecase); <br/> htmlstring = RegEx. replace (htmlstring, @ "<! --. * "," ", Regexoptions. ignorecase); <br/> htmlstring = RegEx. replace (htmlstring, @ "& (quot | #34);", "/" ", regexoptions. ignorecase); <br/> htmlstring = RegEx. replace (htmlstring, @ "& (Amp | #38);", "&", regexoptions. ignorecase); <br/> htmlstring = RegEx. replace (htmlstring, @ "& (LT | #60);", "<", regexoptions. ignorecase); <br/> htmlstring = RegEx. replace (htmlstring, @ "& (GT | #62);", ">", regexoptions. ignorecase ); <Br/> htmlstring = RegEx. replace (htmlstring, @ "& (nbsp | #160);", "", regexoptions. ignorecase); <br/> htmlstring = RegEx. replace (htmlstring, @ "& (iexcl | #161);", "/xA1", regexoptions. ignorecase); <br/> htmlstring = RegEx. replace (htmlstring, @ "& (cent |# 162);", "/xa2", regexoptions. ignorecase); <br/> htmlstring = RegEx. replace (htmlstring, @ "& (pound | #163);", "/xa3", regexoptions. ignorecase); <br/> htmlstring = RegEx. replace (htmlstring, @ "& (copy | #169);", "/xa9", regexoptions. ignorecase); <br/> htmlstring = RegEx. replace (htmlstring, @ "& # (/d +);", "", regexoptions. ignorecase); <br/> htmlstring. replace ("<", ""); <br/> htmlstring. replace (">", ""); <br/> htmlstring. replace ("/R/N", ""); <br/> htmlstring = httpcontext. current. server. htmlencode (htmlstring ). trim (); <br/> return htmlstring; <br/>}< br/> Public String o Utputbysize (string p_strcontent) // paging function <br/>{< br/> string m_strret = ""; <br/> int m_intpagesize = 2500; // Article size per page <br/> int m_intcurrentpage = 1; // set the first page to the initial page <br/> int m_inttotalpage = 0; <br/> int m_intarticlelength = nohtml (p_strcontent ). length; // Article length <br/> If (m_intpagesize <m_intarticlelength) <br/> {// If the page size is greater than the article length, no paging is required. <br/> If (m_intarticlelength % m_intpagesize = 0) <br/> {// set total pages count <Br/> m_inttotalpage = m_intarticlelength/m_intpagesize; <br/>}< br/> else <br/> {// If the totalsize <br/> m_inttotalpage = m_intarticlelength/m_intpagesize + 1; <br/>}< br/> If (request. querystring ["pages"]! = NULL) <br/> {// set current page number <br/> try <br/> {// handle the abnormal address bar value <br/> m_intcurrentpage = convert. toint32 (request. querystring ["pages"]); <br/> If (m_intcurrentpage> m_inttotalpage) <br/> m_intcurrentpage = m_inttotalpage; <br/>}< br/> catch <br/> {<br/> m_intcurrentpage = m_intcurrentpage; <br/>}< br/> // set the page content to get the size of the current page <br/> If (m_intcurrentpage <m_inttotalpage) <br/>{< br/> m _ Intpagesize = m_intcurrentpage <m_inttotalpage? M_intpagesize: (m_intarticlelength-m_intpagesize * (m_intcurrentpage-1); <br/> m_strret + = p_strcontent.substring (m_intpagesize * (m_intcurrentpage-1), m_intpagesize ); <br/>}< br/> else if (m_intcurrentpage = m_inttotalpage) <br/>{< br/> int mm_intpagesize = m_intarticlelength-m_intpagesize * (m_intcurrentpage-1 ); <br/> m_strret + = p_strcontent.substring (m_intarticlelength-mm_intpagesize); <br/>}< br/> string m_strpageinfo = "<p> </P> "; <br/> for (INT I = 1; I <= m_inttotalpage; I ++) <br/>{< br/> if (I = m_intcurrentpage) <br/> m_strpageinfo + = "page" + I + "| "; <br/> else <br/> m_strpageinfo + = "<a href =" news_id "mce_href =" news_id "" + request. querystring ["wzid"] + "_ pages" + I + ". HTML> "+ I +" </a> | "; <br/>}< br/> // display the page number <br/> This. labpagenumber. TEXT = m_strpageinfo; <br/>}< br/> else <br/>{< br/> m_strret + = p_strcontent; <br/>}< br/> return m_strret; <br/>}< br/> protected void page_load (Object sender, eventargs e) <br/>{< br/> sqldatareader DR = shuju. duquzt (int32.parse (request. querystring ["wzid"]); <br/> If (DR = NULL) return; <br/> If (dr. read () <br/>{< br/> This. labcontent. TEXT = outputbysize (Dr ["wzcontent"]. tostring (); // call this function <br/>... </P> <p> controls used on the front-end page: <asp: label id = "labpagenumber" font-size = "14px" runat = "server"> </ASP: Label> 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.