Java String Break breakString(String input, int partLength)

Here you can find the source of breakString(String input, int partLength)

Description

break String

License

Apache License

Declaration

public static String[] breakString(String input, int partLength) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String[] breakString(String input, int partLength) {
        int numParts = input.length() / partLength;
        if (input.length() % partLength > 0)
            numParts++;//from   w ww .j av a 2s.c om
        String[] parts = new String[numParts];
        int startIndex, endIndex;
        for (int i = 0; i < numParts; i++) {
            startIndex = i * partLength;
            endIndex = startIndex + partLength;
            if (endIndex > input.length()) {
                endIndex = input.length();
            }
            parts[i] = input.substring(i * partLength, endIndex);
        }

        return parts;
    }
}

Related

  1. breakString(String remainingStr, String soFar, int maxLineLength)
  2. breakString(String str, int maxLineLenght)
  3. breakString(String string, int l, String newLine)
  4. breakString(String text, int maxsize)