Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8406537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:08:11+00:00 2026-06-09T23:08:11+00:00

I’m trying to split content of a rather long string into pages of content.

  • 0

I’m trying to split content of a rather long string into pages of content. Right now I’m doing this by character (500 characters per page) like this:

//Lets find out how many pages to make
    int pageLength = 500; //how many characters per page
    NSString *text = ((Story *) [self.story objectAtIndex:chapter]).content;
    int NumberOfPages = (text.length/pageLength);
    //NumberOfPages += 1;

    //Build the Pages Array
    NSMutableArray *pageStrings = [[NSMutableArray alloc] init];
    for (int i = 0; i <= (NumberOfPages+1); i++)
    {
        if (i < NumberOfPages) {
            //Load the text like normal
            NSString *contentString = [[NSString alloc]initWithFormat:@"<html><head><style type=text/css>body {font-family: \"%@\"; font-size: %d;}</style></head><body><p>%@</p></body></htlm>",@"helvetica",20,[text substringWithRange:NSMakeRange(i*pageLength,pageLength)]];
            [pageStrings addObject:contentString];
        }
        if (i == NumberOfPages) {
            //on the last page, only load what's available
            NSString *contentString = [[NSString alloc]initWithFormat:@"<html><head><style type=text/css>body {font-family: \"%@\"; font-size: %d;}</style></head><body><p>%@</p></body></htlm>",@"helvetica",20,[text substringWithRange:NSMakeRange(i*pageLength,(text.length-(i*pageLength)))]];
            [pageStrings addObject:contentString];
        }
        if (i > NumberOfPages){
            //add in a blank page on the end
            NSString *contentString = [[NSString alloc]initWithFormat:@"<html><head><style type=text/css>body {font-family: \"%@\"; font-size: %d;}</style></head><body><p>%@</p></body></htlm>",@"helvetica",20,@"What do you do?"];
            [pageStrings addObject:contentString];
        }
    }
    pageContent = [[NSArray alloc] initWithArray:pageStrings];

This works great, but often ends up with words split in the middle. I’m trying to get it to split on the word instead. The string doesn’t have to be exactly 500 characters, just close to it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:08:13+00:00Added an answer on June 9, 2026 at 11:08 pm

    If you want to do it “right” you should look at the NSString method:

    - (void)enumerateSubstringsInRange:(NSRange)range options:(NSStringEnumerationOptions)opts usingBlock:(void (^)(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop))block
    

    You can intelligently enumerate text by words, lines, paragraphs, sentences, and character sequences.

    Session 128, WWDC 2011, “Advanced Text Processing” has some good information about this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.