code: public String[] splitString(String text, int maxChars,
                                  String[] splitValues) {
          String restOfText = text;
          List<String> list = new ArrayList<String>();
          while (restOfText.length() > maxChars) {
              String thisLine = restOfText.substring(0,maxChars);
              int lineEnd = 0;
              for (int i = 0; i < splitValues.length;i++) {
                  int lastIndex = thisLine.lastIndexOf(splitValues[i]);
                  if (lastIndex > lineEnd) {
                      lineEnd = lastIndex;
                  }
              }
              if (lineEnd == 0) {
                  list.add(thisLine);
                  restOfText = restOfText.substring(maxChars);
              }
              else {
                  list.add(thisLine.substring(0,lineEnd));
                  restOfText = restOfText.substring(lineEnd);
              }
  
          }
          list.add(restOfText);
          return list.toArray(new String[list.size()]);
      }
docs: Split the given string on the given split values ensuring the maximum
  number of characters in each token.
  
  @param text The value to split
  @param maxChars The maximum required characters in each split token
  @param splitValues The set of values to split on
  
  @return The array of tokens from splitting the string