指定字段要截断指定长度,超过的用...代替
Java 代码
- /**
- * 字符串过长,则使用"…"替换
- *
- * @param input
- * @param length 显示的字符的个数
- * @return
- */
- public static String omitTooLongString(String input, int length) {
- if (input == null || input.trim().equals(Constant.EMPTY)) {
- return input;
- }
- int len = input.length();
- if (len <= length) {
- return input;
- } else {
- input = input.substring(0, length);
- input += Constant.ENGLISH_ELLIPSIS;
- }
- return input;
- }
调用:
- this.orgDisplayName = StringUtil.omitTooLongString(orgFullName,
- ORG_FULL_NAME_MAX_LENGTH);
JavaScript 代码
- var omitTooLongString = function (input, length) {
- if (!input) {
- return input;
- }
- var len = input.length;
- if (len <= length) {
- return input;
- } else {
- input = input.substring(0, length);
- input += "...";
- }
- return input;
- };
调用:
- omitTooLongString(orgFullName_val, 14)