Here you can find the source of subStringWhiteSpaces(String str, int maxLen)
Parameter | Description |
---|---|
str | a parameter |
maxlen | a parameter |
public static String subStringWhiteSpaces(String str, int maxLen)
//package com.java2s; //License from project: Apache License public class Main { /**//from w w w . j a v a 2s .c o m * Retorna uma sub string de tamanho maximo maxlen, dividindo a string original por espacos * * @param str * @param maxlen * @return */ public static String subStringWhiteSpaces(String str, int maxLen) { if (str == null) return null; if (maxLen < 1) return ""; int size = str.length(); if (maxLen >= size) return str; String ini = str.substring(0, maxLen); String end = str.substring(maxLen, str.length()); if (end.charAt(0) == ' ') return ini; int whitespace = ini.lastIndexOf(' '); if (whitespace == -1) return ini; return ini.substring(0, whitespace); } }