Commit df002405 authored by yanzg's avatar yanzg

修改MQ请求尸体,防止出错

parent 0f6d5671
...@@ -108,6 +108,34 @@ public class StringHelper { ...@@ -108,6 +108,34 @@ public class StringHelper {
return str.toString(); return str.toString();
} }
/**
* 取左边
*
* @param from
* @param size
* @return
*/
public static String left(String from, int size) {
if (from != null) {
return from.substring(0, Math.min(from.length(), size));
}
return StringHelper.EMPTY;
}
/**
* 取右边
*
* @param from
* @param size
* @return
*/
public static String right(String from, int size) {
if (from != null) {
return from.substring(Math.max(from.length() - size, 0));
}
return StringHelper.EMPTY;
}
/** /**
* 传入很多值,返回第一个不等于排除值、空值的值,当全部为排除值时,返回默认值 * 传入很多值,返回第一个不等于排除值、空值的值,当全部为排除值时,返回默认值
......
package helper;
import com.yanzuoguang.util.helper.StringHelper;
import org.junit.Test;
public class TestStringHelper {
@Test
public void test() {
System.out.println(StringHelper.left("100500103", 3));
System.out.println(StringHelper.left("10", 3));
System.out.println(StringHelper.right("100500103", 3));
System.out.println(StringHelper.right("03", 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