io.github.nichetoolkit.rest.util.CommonUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rest-toolkit-utils Show documentation
Show all versions of rest-toolkit-utils Show documentation
Rest toolkit utils project for Spring Boot
The newest version!
package io.github.nichetoolkit.rest.util;
/**
* CommonUtils
* The common utils class.
* @author Cyan ([email protected])
* @since Jdk1.8
*/
public class CommonUtils {
/**
* substring
* The substring method.
* @param content {@link java.lang.String} The content parameter is String
type.
* @param limit {@link java.lang.Integer} The limit parameter is Integer
type.
* @return {@link java.lang.String} The substring return object is String
type.
* @see java.lang.String
* @see java.lang.Integer
*/
public static String substring(String content, Integer limit) {
if (GeneralUtils.isEmpty(content)) {
return null;
}
String result;
String contentTrim = content.replaceAll("\r", "")
.replaceAll("\n", "")
// .replaceAll(" ", "")
.trim();
if (contentTrim.length() > limit) {
result = contentTrim.substring(0, limit).concat("...");
} else {
result = contentTrim;
}
return result;
}
}