File tree Expand file tree Collapse file tree
simple-common/src/main/java/top/cadecode/common/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package top .cadecode .common .util ;
22
3+ import lombok .NonNull ;
4+
35/**
46 * @author Cade Li
57 * @date 2021/7/15
@@ -24,4 +26,49 @@ public static boolean isEmpty(String str) {
2426 public static boolean isTrimEmpty (String str ) {
2527 return str == null || str .trim ().length () == 0 ;
2628 }
29+
30+ /**
31+ * 判断字符串是否包含指定子串
32+ *
33+ * @return boolean
34+ */
35+ public static boolean contains (String str , String subStr ) {
36+ if (str == null || subStr == null ) {
37+ return false ;
38+ }
39+ return str .contains (subStr );
40+ }
41+
42+ /**
43+ * 截取字符串,支持反序负数
44+ *
45+ * @param str 字符串
46+ * @param begin 开始位置
47+ * @return String
48+ */
49+ public static String subString (String str , int begin ) {
50+ return subString (str , begin , str .length ());
51+ }
52+
53+ /**
54+ * 截取字符串,支持反序负数
55+ *
56+ * @param str 字符串
57+ * @param begin 开始位置
58+ * @param end 开始位置
59+ * @return String
60+ */
61+ public static String subString (String str , int begin , int end ) {
62+ if (str == null ) {
63+ return null ;
64+ }
65+ if (begin < 0 ) {
66+ begin = str .length () + begin ;
67+ }
68+ if (end < 0 ) {
69+ end = str .length () + end ;
70+ }
71+ return str .substring (begin , end );
72+ }
73+
2774}
You can’t perform that action at this time.
0 commit comments