0

Hello everyone,
I am having a small problem, does someone know how to break a long string into small groups of 3 characters. I've tried it but its not working.

Here's a sample of my code:

int begindex =0, endindex = 3;
    String plaintext = null;
    String block;
    StringBuffer sbplaintext = new StringBuffer();


try{

  
    while ((input = fin.read()) != -1)   {
       sbplaintext.append((char) input);
    }
    plaintext = sbplaintext.toString();

    for(int i=0; i < plaintext.length();i++){


        begindex += 3;
        endindex += 3;
    }

I got a string buffer "sbplaintext", (convert into string) and my objective is to make a group a 3 chars.

Thanks in advance for your help.

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by neutralfox
0

I believe the String class has a toCharArray method that would help you. Then every 3 indexes are what you are looking for. Otherwise, use a for loop to add every substring of 3 chars to an array.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.