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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:39:45+00:00 2026-05-20T03:39:45+00:00

I cannot get a string broken into fixed length chunks and added to an

  • 0

I cannot get a string broken into fixed length chunks and added to an ArrayList … the code below iterates through as expected, but all the messageToSplit[] upto the last one are null. The last one actually has a value in it.

In the example below if the edit text returned, “01234567890” then “”, “” and “890”.

Pattern p = Pattern.compile(".{4}");
ArrayList<String> myText = new ArrayList<String>();
String[] messageToSplit = TextUtils.split(myStringEditText.getText().toString(), p);
int x = 0;
while(x  <= (myStringEditText.getText().toString().length() / 4)) {
  Toast.makeText(getBaseContext(), x+": '" + messageToSplit[x] + "'", Toast.LENGTH_SHORT).show();
  myText.add(messageToSplit[x]);
  x++;
}
  • 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-20T03:39:45+00:00Added an answer on May 20, 2026 at 3:39 am

    In a split operation, the regex pattern is the separator. For example, if the regex pattern were ;, then 12;34;56 would be split into 12, 34, and 56.

    So in your case 01234567890 is split into "" (the string before 0123), "" (the string between 0123 and 4567) and 890 (the remainder of the string after 4567).

    You probably don’t want to use split but rather something like this:

    Pattern p = Pattern.compile(".{1,4}");
    Matcher regexMatcher = p.matcher(messageToSplit);
    while (regexMatcher.find()) {
        myText.add(regexMatcher.group());
    } 
    

    .{1,4} will match 4 characters if it can, but make do with 1-3 if four are no longer available (which might happen at the end of the string if its length is not a multiple of 4).

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

Sidebar

Related Questions

i know that JCIFS not support ntlm version2 , mean i cannot use spring-nltm
this is the follow-up to my question about getting a div's content. the second
when ntlmprocessingfilter fail (entered wrong username and password), it is forwarded to form-login page.
I am trying to retrieve all the email gruops and their mail address from
I am trying to implement the MyLocationOverlay class from google maps. However, when I
In the following example (yes, I am coding on my timeline while I try
I've created a webbrowser in C# and I want to be able to select
I'm working on my first COM project that is importing a c# DLL with
I have a custom object that I am trying to bind to a control.
I am trying to have a textfield with an initial value, where if you

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.