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

  • SEARCH
  • Home
  • 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 9234041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:41:47+00:00 2026-06-18T06:41:47+00:00

I am trying to create a function in javascript that will take a string

  • 0

I am trying to create a function in javascript that will take a string of text as a paramater, and then format it for me by adding \n to the string, which will form paragraphs.

  • each paragraph can only be 32 chars in length
  • i have to make sure that the words are not cut in half, when going to the next paragraph”

example String:

"If we listened to our intellect, we'd never have a love affair. We'd never have a friendship. We'd never go into business, because we'd be cynical. Well, that's nonsense. You've got to jump off cliffs all the time and build your wings on the way down."

after format should be like:

If we listened to our intellect, \n
we'd never have a love affair. \n
We'd never have a friendship.\n
We'd never go into business, \n
because we'd be cynical. Well, \n
that's nonsense. You've got to  \n
jump off cliffs all the time and \n
build your wings on the way down"

I am not sure how i would approach this problem, and im not expecting anyone to solve the whole solution, i just want a starting point, i am having difficulties with how to deal with spaces and words, and when to insert the \n into the string.

  • 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-18T06:41:49+00:00Added an answer on June 18, 2026 at 6:41 am

    Here’s an algorithm for you:

    take your string; chop it up in two pieces: left (first 32 chars), right (the rest)
    while right != empty
     if length(left) == 32
        while last character of left != space
           take last char off of left, prepend it to right
    
     print left
     new left = first 32 chars of right; right = rest
    end while
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a Javascript function that will return all javascript files
I'm trying to create some javascript code that will display a javascript form (from
Possible Duplicate: Reset JavaScript Counter? I'm trying to create a function that will trigger
I'm trying to create a Regex test in JavaScript that will test a string
I'm trying to create javascript closure that will tell me if the function has
I'm having a problem trying to create a Javascript function that checks all the
I am trying to create a function which will give me alphabet position when
I am trying to create a function that will block access to some of
Hello there i'm trying to create a form with Zend_Form that will enable my
I am trying to create a simple function that can take a parameter and

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.