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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:06:12+00:00 2026-05-18T01:06:12+00:00

I would like some guidance on how to split a string into N number

  • 0

I would like some guidance on how to split a string into N number of separate strings based on a arithmetical operation; for example string.length()/300.

I am aware of ways to do it with delimiters such as

testString.split(",");

but how does one uses greedy/reluctant/possessive quantifiers with the split method?


Update: As per request a similar example of what am looking to achieve;

String X = "32028783836295C75546F7272656E745C756E742E657865000032002E002E005C0"

Resulting in X/3 (more or less… done by hand)

X[0] = 32028783836295C75546F

X[1] = 6E745C756E742E6578650

x[2] = 65000032002E002E005C0

Dont worry about explaining how to put it into the array, I have no problem with that, only on how to split without using a delimiter, but an arithmetic operation

  • 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-05-18T01:06:13+00:00Added an answer on May 18, 2026 at 1:06 am

    You could do that by splitting on (?<=\G.{5}) whereby the string aaaaabbbbbccccceeeeefff would be split into the following parts:

    aaaaa
    bbbbb
    ccccc
    eeeee
    fff
    

    The \G matches the (zero-width) position where the previous match occurred. Initially, \G starts at the beginning of the string. Note that by default the . meta char does not match line breaks, so if you want it to match every character, enable DOT-ALL: (?s)(?<=\G.{5}).

    A demo:

    class Main {
      public static void main(String[] args) {
        int N = 5;
        String text = "aaaaabbbbbccccceeeeefff";
        String[] tokens = text.split("(?<=\\G.{" + N + "})");
        for(String t : tokens) {
          System.out.println(t);
        }
      }
    }
    

    which can be tested online here: http://ideone.com/q6dVB

    EDIT

    Since you asked for documentation on regex, here are the specific tutorials for the topics the suggested regex contains:

    • \G, see: http://www.regular-expressions.info/continue.html
    • (?<=...), see: http://www.regular-expressions.info/lookaround.html
    • {...}, see: http://www.regular-expressions.info/repeat.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like seek some guidance in writing a process profiler which runs in
I would like some practical guidance on when I should use a Domain Specific
I am developing my first windows mobile application and would like some guidance on
I would like some guidance as to the state of the art in writing
I would like to start working with Zend Framework 2 and need some guidance
Looking for some guidance on feasibility and implementation.. I would like to accomplish the
I would like some help about an Android Application. I used the new Google
I would like some help parsing a dynamic (folder.subfolders) xml with xslt, I tried
I would like some container that I can very efficiently append a variable amount
I would like some sugestion on how to design a table that gets like

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.