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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:40:59+00:00 2026-06-18T19:40:59+00:00

I apologize if this is a duplicate but I can’t seem to find anything

  • 0

I apologize if this is a duplicate but I can’t seem to find anything out there that involves splitting a string based on a character count. For example, let’s say I have the following string:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ullamcorper, eros 
sed porta dapibus, nunc nibh iaculis tortor, in rhoncus quam orci sed ante. Sed 
ac dictum nibh.

Now, I can split the string based on a specific character, but how can I split this string after the nth character, regardless of what it is? Something like this, only with a working syntax is what I am thinking:

max_char = n #where n is the number of characters to split after
MyText = 'User input string. This is usually at least a paragraph long.'
char_count = len(MyText)
if char_count > max_char:
 #split string at max_char, create variables: MyText1 and MyText2

Any help would be appreciated. Thanks!

Update

I wanted to post this update since my question only approached half of my problem. Thanks to Martijin’s answer below I easily sliced the string above. However, since the string I was making edits to was user submitted, I ran into the problem of slicing words in half. In order to fix this problem, I used a combination of rsplit and rstrip to break up the paragraph correctly. Just in case someone out there is facing the same issues as me here is the code I used to make it work:

line1 = note[:36]
line2 = note[36:]

if not line1.endswith(' ', 1):
 line2_2 = line1.rsplit(' ')[-1]
 line1_1 = line1.rstrip(line2_2)
 line2_2 = line2_2 + line2
 line1 = ''
 line2 = ''

Now, I’m sure there is a more efficient/elegant way of doing this, but this still works so hopefully somebody can benefit from it. Thanks!

  • 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-18T19:41:01+00:00Added an answer on June 18, 2026 at 7:41 pm

    You are looking for slicing:

    MyText1, MyText2 = MyText[:max_char], MyText[max_char:]
    

    Python strings are sequences, to select the first max_char characters, simply use a slice to select those, and for the second half select everything starting at max_char until the end.

    This is covered in the Python tutorial as well.

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

Sidebar

Related Questions

I apologize if this is a duplicate but I did not find anything that
I apologize if this is a duplicate, but I can't seem to find this
I apologize if this is a duplicate but I couldn't find any solutions that
I must apologize if this is a duplicate question, but I can't seem to
This question is prob a duplicate (but I can't find it) so I apologize
I apologize for this seemingly relatively simple task that I can't figure out. I
I apologize if this may seem like a duplicate but I have not seen
I apologize if this is a duplicate, but I couldn't find any concrete examples
Apologies if this is a duplicate but I couldn't find anything concrete as an
I apologize if this is a duplicate post, but I couldn't find the answer

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.