Commit 5a2d7d16 authored by yanzg's avatar yanzg

修改实体位置

parent da48caf3
......@@ -710,48 +710,6 @@ public class StringHelper {
return sb.toString();
}
/**
* 去掉两边的空格
*
* @param from 需要去掉空格的字符串
* @return 去掉字符串的值
*/
public static String trim(String from) {
if (from == null) {
return EMPTY;
}
return from.trim();
}
/**
* 去掉左边的字符串
*
* @param from
* @param left
* @return
*/
public static String trimLeft(String from, String... left) {
int pos = 0;
boolean isHandle;
do {
isHandle = false;
for (String item : left) {
int size = item.length();
if (from.indexOf(item, pos) == pos) {
isHandle = true;
pos += size;
continue;
}
}
} while (isHandle);
if (pos > 0) {
return from.substring(pos);
} else {
return from;
}
}
/**
* 对比字符串是否相等,不区分大小写
*
......@@ -1177,40 +1135,102 @@ public class StringHelper {
return sb.toString();
}
/**
* 删除开头字符串
* 去掉两边的空格
*
* @param inStr
* @param prefix
* @param from 需要去掉空格的字符串
* @return 去掉字符串的值
*/
public static String trim(String from) {
if (from == null) {
return EMPTY;
}
return from.trim();
}
/**
* 去掉两边的空格
*
* @param from 需要去掉空格的字符串
* @return 去掉字符串的值
*/
public static String trim(String from, String... suffix) {
if (from == null) {
return EMPTY;
}
return trimRight(trimLeft(from, suffix), suffix);
}
/**
* 去掉左边的字符串
*
* @param from
* @param suffix
* @return
*/
public static String trimStart(String inStr, String prefix) {
if (inStr == null) {
return null;
public static String trimLeft(String from, String... suffix) {
if (from == null) {
return EMPTY;
}
boolean handle = true;
while (handle) {
handle = false;
for (String prefix : suffix) {
if (from.startsWith(prefix)) {
from = from.substring(prefix.length());
handle = true;
}
if (inStr.startsWith(prefix)) {
String ret = inStr.substring(prefix.length());
return trimStart(ret, prefix);
}
return inStr;
}
return from;
}
/**
* 删除末尾字符串
* 去掉左边的字符串
*
* @param inStr
* @param from
* @param suffix
* @return
*/
public static String trimEnd(String inStr, String suffix) {
if (inStr == null) {
return null;
public static String trimRight(String from, String... suffix) {
if (from == null) {
return EMPTY;
}
boolean handle = true;
while (handle) {
handle = false;
for (String prefix : suffix) {
if (from.endsWith(prefix)) {
from = from.substring(0, from.length() - prefix.length());
handle = true;
}
}
}
return from;
}
if (inStr.endsWith(suffix)) {
String ret = inStr.substring(0, inStr.length() - suffix.length());
return trimEnd(ret, suffix);
/**
* 删除开头字符串
*
* @param from
* @param suffix
* @return
*/
public static String trimStart(String from, String... suffix) {
return trimLeft(from, suffix);
}
return inStr;
/**
* 删除末尾字符串
*
* @param from
* @param suffix
* @return
*/
public static String trimEnd(String from, String suffix) {
return trimRight(from, suffix);
}
}
......@@ -12,4 +12,13 @@ public class TestStringHelper {
System.out.println(StringHelper.right("03", 3));
}
@Test
public void testTrim() {
System.out.println(StringHelper.trimLeft("100500103", "1", "0"));
System.out.println(StringHelper.trimRight("100500103", "3", "0"));
System.out.println(StringHelper.trim("100500103", "1", "0", "3"));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment