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 7887871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:41:33+00:00 2026-06-03T05:41:33+00:00

Imagine I have 150 characters long string. I would like to divide it into

  • 0

Imagine I have 150 characters long string. I would like to divide it into 3 parts, each max 50 characters long. The trick is I also have to keep words intact while dividing the string into 3 parts.

I could use substr and check if it cut the word into half or not. I would like to know if there is any other elegant way to do this.

I also have to keep it in mind that the string might have less than 150 characters. For example if it is 140 characters long then it should be 50 + 50 + 40.

In case if it is less than 100 than it should be 50 + 50. If it is 50 characters or less it shouldn’t divide the string.

I would be glad to hear your ideas / ways to approach this.

Thank you in advance for your time and concern.

  • 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-03T05:41:34+00:00Added an answer on June 3, 2026 at 5:41 am

    Sounds like you just want the php function wordwrap()

     string wordwrap ( string $str [, int $width = 75 [, string $break = “\n” [, bool $cut = false ]]] )

    Wraps a string to a given number of characters using a string break character.

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

Sidebar

Related Questions

Imagine I have String in C#: I Don’t see ya.. I want to remove
Imagine I have the folling XML file: <a>before<b>middle</b>after</a> I want to convert it into
Imagine I have table like this: id:Product:shop_id 1:Basketball:41 2:Football:41 3:Rocket:45 4:Car:86 5:Plane:86 Now, this
Imagine I have a long, multi-word line of text in a DIV: Hello there,
Imagine we have a set of entities each of which has its state: free,
Imagine I have something like this: def example = { def temp = ConferenceUser.findAllByUser(User.get(session.user))
Imagine I have one common functionality: series and number (string and integer) of some
Imagine I have the following string : set(SEXY_STRING I love CMake) then I want
Imagine I have 3 lines of text for example like below: Line 1: This
Imagine I have a data frame with data like this: A | B |

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.