Java Utililty Methods String Slice

List of utility methods to do String Slice

Description

The list of methods to do String Slice are organized into topic(s).

Method

String[]slice(int theNum, String[] theStringArray)
slice
if (theNum < theStringArray.length) {
    String[] t = new String[theStringArray.length - theNum];
    for (int i = theNum; i < theStringArray.length; i++) {
        t[i - theNum] = theStringArray[i];
    return t;
return theStringArray;
...
String[]slice(String contents, int CONTENT_COLUMN_SIZE)
Database column is limited to fixed length.
int columnCount = contents.length() / CONTENT_COLUMN_SIZE;
String[] contentArray = new String[columnCount + 1];
int beginIndex = 0;
int endIndex = 0;
for (int i = 0; i <= columnCount; i++) {
    if (beginIndex + CONTENT_COLUMN_SIZE < contents.length()) {
        endIndex = beginIndex + CONTENT_COLUMN_SIZE;
    } else {
...
Stringslice(String input, int index, int length)
Returns a substring starting at the given index for the given length.
if (input == null || input.equals(""))
    return input;
String output = "";
int inputLength = input.length(), endIndex = 0;
if (length < 0) {
    if (index < 0) {
        endIndex = index + inputLength + 1;
    } else {
...
String[]slice(String line)
Turns a line with strings separated by one or more spaces into a String array.
return line.trim().split("\\s+");
Stringslice(String value, int beginOffset, int endOffset, boolean trim)
Return a slice (substring) of the passed in value, optionally trimmed.
String retval = value.substring(beginOffset, endOffset + 1);
if (trim) {
    retval = retval.trim();
return retval;
StringsliceAndMatch(String fstring, String rstring)
slice And Match
String resultString = "";
for (int i = 0; i < fstring.length(); i++) {
    String subString = fstring.substring(i, fstring.length());
    if (rstring.startsWith(subString)) {
        resultString += subString + rstring.substring(subString.length());
        break;
    resultString += fstring.charAt(i);
...
intsliceLength(int start, int stop, long step)
Make step a long in case adding the start, stop and step together overflows an int.
int ret;
if (step > 0) {
    ret = (int) ((stop - start + step - 1) / step);
} else {
    ret = (int) ((stop - start + step + 1) / step);
if (ret < 0) {
    return 0;
...