liulin
2024-07-30 ce04dfcdd664df7e791a63800cab2cd2d12e878c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
package com.lunhan.xxx.common.util;
 
import com.lunhan.xxx.common.ConstantFactory;
import com.lunhan.xxx.common.security.MD5Util;
import org.apache.commons.lang3.EnumUtils;
import org.apache.commons.lang3.StringUtils;
 
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
 
/**
 * 字符串处理类
 * @author linliu
 * @date   2018-12-28
 */
public final class StringUtil {
    //region 常量
    private static final String REGX_MOBILEPHONE = "^((\\+86)|(\\(\\+86\\))-)?[0-9]{11}$";
 
    private static final String REGX_TELEPHONE = "^((\\+86)|(\\(\\+86\\))-)?(((0[1,2]{1}\\d{1})?-?\\d{8})|((0[3-9]{1}\\d{2})?-?\\d{7,8}))$";
 
    private static final String REGX_IDCARD = "^([0-9]{17}[0-9X]{1})|([0-9]{15})$";
 
    private static final String REGX_WEBURL = "^(((file|gopher|news|nntp|telnet|http|ftp|https|ftps|sftp)://)|(www\\.))+(([a-zA-Z0-9\\._-]+\\.[a-zA-Z]{2,6})|([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}))(/[a-zA-Z0-9\\&%_\\./-~-]*)?$";
 
    private static final String REGX_EMAIL = "^\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
 
    private static final String REGX_MONEY = "^\\d{1,12}(?:\\.\\d{1,4})?$";
 
    private static final String DEFAULT = "utf-8";
    //endregion
 
    private StringUtil() {
        throw new IllegalStateException("Utility class");
    }
 
    /**
     *  从当前对象移除头尾指定字符
     * @author xiangyuanzhang
     * @date   2018-12-25
     * @param source 原始字符串
     * @param trimChar 移除字符串
     */
    public String trim(String source, String trimChar) {
        if(source==null){
            return "";
        }
        source = source.trim();
        if(source.isEmpty()){
            return "";
        }
        String beginChar = source.substring(0, 1);
        if (beginChar.equalsIgnoreCase(trimChar)) {
            source = source.substring(1, source.length());
        }
        String endChar = source.substring(source.length() - 1, source.length());
        if (endChar.equalsIgnoreCase(trimChar)) {
            source = source.substring(0, source.length() - 1);
        }
        return source;
    }
 
    /**
     *  从当前对象移除头部指定字符
     * @author xiangyuanzhang
     * @date   2018-12-25
     * @param source 原始字符串
     * @param trimChar 移除字符串
     */
    public String trimStart(String source, String trimChar) {
        if(source==null){
            return "";
        }
        source = source.trim();
        if(source.isEmpty()){
            return "";
        }
        String beginChar = source.substring(0, 1);
        if (beginChar.equalsIgnoreCase(trimChar)) {
            source = source.substring(1, source.length());
        }
        return source;
    }
 
    /**
     *  从当前对象移除尾部指定字符
     * @author xiangyuanzhang
     * @date   2018-12-25
     * @param source 原始字符串
     * @param trimChar 移除字符串
     */
    public String trimEnd(String source, String trimChar) {
        if(source==null){
            return "";
        }
        source = source.trim();
        if(source.isEmpty()){
            return "";
        }
        String endChar = source.substring(source.length() - 1, source.length());
        if (endChar.equalsIgnoreCase(trimChar)) {
            source = source.substring(0, source.length() - 1);
        }
        return source;
    }
 
    /**
     * 字符串枚举值转成枚举对象
     * @author linliu
     * @date   2018-12-24
     * @param enumType 枚举类型
     * @param value 枚举值
     * @param <T> 枚举类型
     * @return 枚举对象
     */
    public static <T extends Enum<T>> T parseEnum(Class<T> enumType, String value) {
        if(isNullOrEmpty(value)) {
            return null;
        }
 
        T result = null;
        try {
            T[] values = enumType.getEnumConstants();
            Method getValue = enumType.getMethod("getValue");
 
            for (T e : values) {
                if(getValue.invoke(e).toString().equals(value)) {
                    result = e;
                    break;
                }
            }
        } catch (Exception e) {
            //TODO log
        }
        return result;
    }
 
    /**
     * 字符串枚举值转成枚举对象
     * @author linliu
     * @date   2018-12-24
     * @param enumType 枚举类型
     * @param name 枚举名称
     * @param <T> 枚举类型
     * @return 枚举对象
     */
    public static <T extends Enum<T>> T parseEnumByName(Class<T> enumType, String name) {
        if(isNullOrEmpty(name)) {
            return null;
        }
 
        T result = null;
        try {
            result = EnumUtils.getEnum(enumType, name);
        } catch (Exception e) {
            //TODO log
        }
        return result;
    }
 
    /**
     * 判断枚举是否申明了传入枚举值
     * @author linliu
     * @date   2018-12-24
     * @param enumType 枚举类型
     * @param value 枚举值
     * @param <T> 枚举类型
     * @return 是否包含
     */
    public static <T extends Enum<T>> boolean isEnum(Class<T> enumType, String value) {
        return (null != parseEnum(enumType, value));
    }
 
    /**
     * 判断枚举是否申明了传入枚举值
     * @author linliu
     * @date   2018-12-24
     * @param enumType 枚举类型
     * @param name 枚举名称
     * @param <T> 枚举类型
     * @return 是否包含
     */
    public static <T extends Enum<T>> boolean isEnumName(Class<T> enumType, String name) {
        return EnumUtils.isValidEnum(enumType, name);
    }
 
    /**
     * 字符串是否为空
     * @author linliu
     * @date   2018-12-25
     * @param str 字符串
     * @return 是否为空
     */
    public static boolean isNullOrEmpty(String str){
        return  (str==null || str.equals("") || str.replace(" ","").length() == 0);
    }
 
    /**
     * 字符串非空
     * @author linliu
     * @date   2018-12-25
     * @param str 字符串
     * @return 是否非空
     */
    public static boolean isNotNullOrEmpty(String str){
        return  !isNullOrEmpty(str);
    }
 
    /**
     * 集合,使用英文逗号“,”拼接成一个字符串
     * @param list 集合
     */
    public static String join(Collection<String> list){
        return StringUtil.join(list, ",");
    }
    /**
     * 集合,使用指定的字符,拼接成一个字符串
     * @param list 集合
     * @param separator 拼接字符
     */
    public static String join(Collection<String> list, String separator){
        if(ListUtil.isNullOrEmpty(list)){
            return "";
        }
        return StringUtils.join(list.toArray(), separator);
    }
    /**
     * 数组,使用英文逗号“,”拼接成一个字符串
     * @param array 数组
     */
    public static String join(String[] array){
        return StringUtil.join(array, ",");
    }
    /**
     * 数组,使用指定的字符,拼接成一个字符串
     * @param array 数组
     * @param separator 拼接字符
     */
    public static String join(String[] array, String separator){
        if(array == null){
            return "";
        }
        return StringUtils.join(array, separator);
    }
 
    /**
     * 集合,使用英文逗号“,”拼接成一个字符串
     * @param list 集合
     */
    public static String joinNumber(Collection<Number> list){
        return StringUtil.joinNumber(list, ",");
    }
    /**
     * 集合,使用指定的字符,拼接成一个字符串
     * @param list 集合
     * @param separator 拼接字符
     */
    public static String joinNumber(Collection<Number> list, String separator){
        if(ListUtil.isNullOrEmpty(list)){
            return "";
        }
        return StringUtils.join(list.toArray(), separator);
    }
    /**
     * 数组,使用英文逗号“,”拼接成一个字符串
     * @param array 数组
     */
    public static String joinNumber(Number[] array){
        return joinNumber(array, ",");
    }
    /**
     * 数组,使用指定的字符,拼接成一个字符串
     * @param array 数组
     * @param separator 拼接字符
     */
    public static String joinNumber(Number[] array, String separator){
        if(array == null){
            return "";
        }
        return StringUtils.join(array, separator);
    }
 
    /**
     * base64解码(utf-8编码)
     * @author linliu
     * @date   2019-06-14
     * @param str 密文字符串
     * @return 解码后的明文
     */
    public static String base64Encode(String str) {
        return base64Encode(str, DEFAULT);
    }
    /**
     * base64解码
     * @author linliu
     * @date   2019-06-14
     * @param str 密文字符串
     * @param encoding 编码格式[默认utf-8]
     * @return 解码后的明文
     */
    public static String base64Encode(String str, String encoding) {
        if(isNullOrEmpty(str)) {
            return "";
        }
        if(isNullOrEmpty(encoding)) {
            encoding = DEFAULT;
        }
        byte[] bytes = str.getBytes(Charset.forName(encoding));
        return Base64.getEncoder().encodeToString(bytes);
    }
 
    /**
     * base64解码(utf-8编码)
     * @author linliu
     * @date   2019-06-14
     * @param str 密文字符串
     * @return 解码后的明文
     */
    public static String base64Decode(String str) {
        return base64Decode(str, DEFAULT);
    }
    /**
     * base64解码
     * @author linliu
     * @date   2019-06-14
     * @param str 密文字符串
     * @param encoding 编码格式[默认utf-8]
     * @return 解码后的明文
     */
    public static String base64Decode(String str, String encoding) {
        if(isNullOrEmpty(str)) {
            return "";
        }
        if(isNullOrEmpty(encoding)) {
            encoding = DEFAULT;
        }
        byte[] bytes = Base64.getDecoder().decode(str);
        return new String(bytes, Charset.forName(encoding));
    }
 
    /**
     * 传入字符串是否是有效的手机号码
     * @param str 字符串
     */
    public static boolean isMobilePhone(String str) {
        return Pattern.matches(REGX_MOBILEPHONE, str);
    }
 
    /**
     * 传入字符串是否是有效的座机号码
     * @param str 字符串
     */
    public static boolean isTelPhone(String str) {
        return Pattern.matches(REGX_TELEPHONE, str);
    }
 
    /**
     * 传入字符串是否是有效的身份证号码
     * @param str 字符串
     */
    public static boolean isIdCard(String str) {
        return Pattern.matches(REGX_IDCARD, str);
    }
 
    /**
     * 传入字符串是否是有效的网址
     * @param str 字符串
     */
    public static boolean isWebUrl(String str) {
        return Pattern.matches(REGX_WEBURL, str);
    }
 
    /**
     * 传入字符串是否是有效的电子邮件邮箱地址
     * @param str 字符串
     */
    public static boolean isEmail(String str) {
        return Pattern.matches(REGX_EMAIL, str);
    }
 
    /**
     * 传入字符串是否是有效的金额
     * @param str 字符串
     */
    public static boolean isMoney(String str) {
        return Pattern.matches(REGX_MONEY, str);
    }
 
    /**
     * 是否满足正则表达式规则
     * @author linliu
     * @date   2019-01-04
     * @param str 字符串
     * @param regex 正则表达式
     * @return 是否匹配
     */
    public static Boolean isMatch(String str,String regex) {
        if(StringUtil.isNullOrEmpty(str)) {
            return Boolean.FALSE;
        }
        return Pattern.matches(regex, str);
    }
 
    /**
     * 正则获取Xml中的内容
     * @author xiangyuanzhang
     * @date   2019-01-09
     * @param xml 传入的xml字符串
     * @param label 指定的标签中的内容
     */
    public static String regexXml(String xml, String label) {
        String context = "";
        String rgex = "<" + label + ">(.*?)</" + label + ">";
        Pattern pattern = Pattern.compile(rgex,Pattern.CASE_INSENSITIVE);
        Matcher m = pattern.matcher(xml);
        List<String> list = new ArrayList<>();
        int i = 1;
        while (m.find()) {
            list.add(m.group(i));
            i++;
        }
        if (!list.isEmpty()) {
            context = list.get(0);
        }
        return context;
    }
 
    /**
     * 获取<![CDATA 中内容
     *  @author xiangyuanzhang
     *  @date   2019-01-14
     * @param str
     * @return
     */
    public static String getCDATAContent(String str) {
        Pattern p = Pattern.compile(".*<!\\[CDATA\\[(.*)\\]\\]>.*");
        Matcher m = p.matcher(str);
        if(m.matches()) {
           return m.group(1);
        }
        return str;
    }
 
    /**
     * 将传入字符串转成 Integer 类型
     * @param str 字符串
     */
    public static int parseInt(String str) {
        return Integer.parseInt(str);
    }
 
    /**
     * 将传入字符串转成 Long 类型
     * @param str 字符串
     */
    public static long parseLong(String str) {
        return Long.parseLong(str);
    }
 
    /**
     * 将传入字符串转成精度为2位小数的 BigDecimal 类型
     * @param str 字符串
     */
    public static BigDecimal parseBigDecimal(String str) {
        return parseBigDecimal(str, Integer.parseInt("2"));
    }
 
    /**
     * 将传入字符串转成指定精度的 BigDecimal 类型
     * @param str 字符串
     */
    public static BigDecimal parseBigDecimal(String str, Integer length) {
        BigDecimal bd = new BigDecimal(str);
        return bd.setScale(length, BigDecimal.ROUND_HALF_UP);
    }
 
    /**
     * 传入字符串是否是有效的 BigDecimal
     * @param str 字符串
     */
    public static boolean isBigDecimal(String str) {
        try{
            if(isNullOrEmpty(str)) {
                return false;
            }
            new BigDecimal(str);
            return true;
        }catch (NumberFormatException e){
           return false;
        }
    }
 
    /**
     * 将传入指定格式的字符串转成 Calendar 类型(默认“yyyy-MM-dd HH:mm:ss”)
     * @param str 时间字符串
     * @param format 时间格式
     */
    public static Calendar parseDate(String str, String... format) {
        String f = ConstantFactory.STR_DATE_FULL;
        if(format.length>0) {
            f = format[0];
        }
        return CalendarUtil.fromStr(str, f);
    }
 
    /**
     * md5加密
     * @param content 待加密明文字符串
     */
    public static String md5(String content) {
        return MD5Util.encrypt(content);
    }
 
    /**
     * 集合,使用英文逗号“,”拼接成一个字符串
     * @param list 集合
     */
    public static String joinInt(List<Integer> list){
        return joinInt(list, ",");
    }
    /**
     * 集合,使用指定的字符,拼接成一个字符串
     * @param list 集合
     * @param separator 拼接字符
     */
    public static String joinInt(List<Integer> list, String separator){
        if(ListUtil.isNullOrEmpty(list)){
            return "";
        }
        return StringUtils.join(list.toArray(), separator);
    }
 
    /**
     * 数组,使用英文逗号“,”拼接成一个字符串
     * @param array 数组
     */
    public static String joinInt(Integer[] array){
        return joinInt(array, ",");
    }
    /**
     * 数组,使用指定的字符,拼接成一个字符串
     * @param array 数组
     * @param separator 拼接字符
     */
    public static String joinInt(Integer[] array, String separator){
        if(array == null){
            return "";
        }
        return StringUtils.join(array, separator);
    }
 
    /**
     * 将传入字符串按指定分隔符,拆分成数组
     * @param str 字符串
     * @param splitChar 分隔符
     */
    public static String[] split(String str, String splitChar) {
        if(StringUtil.isNullOrEmpty(str)) {
            return new String[0];
        }
        return str.split(splitChar);
    }
    /**
     * 将传入字符串按英文逗号“,”分隔,拆分成数组
     * @param str 字符串
     */
    public static String[] split(String str) {
        if(StringUtil.isNullOrEmpty(str)) {
            return new String[0];
        }
        return str.split("\\,");
    }
 
    /**
     * 将传入字符串按指定分隔符,拆分成集合
     * @param str 字符串
     * @param splitChar 分隔符
     */
    public static List<String> splitList(String str, String splitChar) {
        if(StringUtil.isNullOrEmpty(str)) {
            return new ArrayList<>();
        }
        return ListUtil.toList(split(str, splitChar));
    }
    /**
     * 将传入字符串按英文逗号“,”分隔,拆分成集合
     * @param str 字符串
     */
    public static List<String> splitList(String str) {
        if(StringUtil.isNullOrEmpty(str)) {
            return new ArrayList<>();
        }
        return splitList(str, ",");
    }
 
    /**
     * 将传入字符串按指定分隔符,拆分成集合
     * @param str 字符串
     * @param splitChar 分隔符
     */
    public static List<Integer> splitIntList(String str, String splitChar) {
        if(StringUtil.isNullOrEmpty(str)) {
            return new ArrayList<>();
        }
        return ListUtil.toIntList(splitList(str, splitChar));
    }
    /**
     * 将传入字符串按英文逗号“,”分隔,拆分成集合
     * @param str 字符串
     */
    public static List<Integer> splitIntList(String str) {
        if(StringUtil.isNullOrEmpty(str)) {
            return new ArrayList<>();
        }
        return splitIntList(str, ",");
    }
 
    /**
     * 将传入字符串按指定分隔符,拆分成集合
     * @param str 字符串
     * @param splitChar 分隔符
     */
    public static List<Long> splitLongList(String str, String splitChar) {
        if(StringUtil.isNullOrEmpty(str)) {
            return new ArrayList<>();
        }
        return ListUtil.toLongList(splitList(str, splitChar));
    }
    /**
     * 将传入字符串按英文逗号“,”分隔,拆分成集合
     * @param str 字符串
     */
    public static List<Long> splitLongList(String str) {
        if(StringUtil.isNullOrEmpty(str)) {
            return new ArrayList<>();
        }
        return splitLongList(str, ",");
    }
 
    /**
     * 集合,使用英文逗号“,”拼接成一个字符串
     * @param list 集合
     */
    public static String joinLong(Collection<Long> list) {
        return StringUtil.joinLong(list, ",");
    }
    /**
     * 集合,使用指定的字符,拼接成一个字符串
     * @param list 集合
     * @param separator 拼接字符
     */
    public static String joinLong(Collection<Long> list, String separator) {
        if(ListUtil.isNullOrEmpty(list)){
            return "";
        }
        return StringUtils.join(list.toArray(), separator);
    }
 
    /**
     * 数组,使用英文逗号“,”拼接成一个字符串
     * @param array 数组
     */
    public static String joinLong(Long[] array) {
        return joinLong(array, ",");
    }
    /**
     * 数组,使用指定的字符,拼接成一个字符串
     * @param array 数组
     * @param separator 拼接字符
     */
    public static String joinLong(Long[] array, String separator){
        if(array == null){
            return "";
        }
        return StringUtils.join(array, separator);
    }
 
    /**
     * 将字符串按英文逗号“,”分割,拆分成日期集合
     * @param str
     * @param dateFormat
     * @return
     */
    public static List<Date> splitListDate(String str, String dateFormat) {
        return splitListDate(str, dateFormat, ",");
    }
    /**
     * 将字符串按指定分隔符,拆分成日期集合
     * @param str 字符串
     * @param dateFormat 日期格式
     * @return
     */
    public static List<Date> splitListDate(String str, String dateFormat, String separator) {
        if(StringUtil.isNullOrEmpty(str)) {
            return new ArrayList<>();
        }
        List<String> lstDate = splitList(str, separator);
        return lstDate.stream().map(d -> {
            try {
                return CalendarUtil.fromStr(d, dateFormat).getTime();
            } catch (Exception e) {
                return null;
            }
        }).collect(Collectors.toList());
    }
 
    /**
     * 按指定字符串分割字符串
     * @author linliu
     * @date   2019-06-19
     * @param str 字符串
     * @param onceQuantity 拆分后单个字符串的字符数
     */
    public static String[] split(String str, Integer onceQuantity) {
        if(StringUtil.isNullOrEmpty(str)) {
            return new String[]{};
        }
        if(Integer.valueOf(0).compareTo(onceQuantity)>-1) {
            onceQuantity = str.length();
        }
        int size = str.length() / onceQuantity;
        String[] result = new String[size];
        if(size==1) {
            result[0] = str;
            return result;
        }
        for (int idx=0; idx<size; idx++) {
            result[idx] = substring(str, onceQuantity*idx, onceQuantity*(idx+1));
        }
        return result;
    }
 
    /**
     * 按指定字符串分割字符串
     * @author linliu
     * @date   2019-06-19
     * @param str 字符串
     * @param onceQuantity 拆分后单个字符串的字符数
     */
    public static List<String> splitList(String str, Integer onceQuantity) {
        if(StringUtil.isNullOrEmpty(str)) {
            return new ArrayList<>();
        }
        if(Integer.valueOf(0).compareTo(onceQuantity)>-1) {
            onceQuantity = str.length();
        }
        int size = str.length() / onceQuantity;
        List<String> result = new ArrayList<>();
        if(size==1) {
            result.add(str);
            return result;
        }
        if(str.length()%onceQuantity != 0) {
            size += 1;
        }
        for (int idx=0; idx<size; idx++) {
            result.add(substring(str, onceQuantity*idx, onceQuantity*(idx+1)));
        }
        return result;
    }
 
    /**
     * 分割字符串,如果开始位置大于字符串长度,返回空
     * @author linliu
     * @date   2019-06-19
     * @param str 原始字符串
     * @param start 开始位置
     * @param end 结束位置
     */
    public static String substring(String str, Integer start, Integer end) {
        if (StringUtil.isNullOrEmpty(str) || start > str.length()) {
            return "";
        }
        if (end > str.length()) {
            return str.substring(start, str.length());
        } else {
            return str.substring(start, end);
        }
    }
 
    /**
     * 截取字符串长度
     * @param content 字符串
     * @param length 截取长度
     */
    public static String cutStr(String content, Integer length) {
       return StringUtil.substring(content, 0, length);
    }
 
    /**
     * 判断是否为空,如果为空返回空字符串
     * @param str 字符串
     */
    public static String getStringDefault(String str) {
        if (StringUtil.isNullOrEmpty(str)) {
            return "";
        }
        return str;
    }
 
    /**
     * 将小驼峰字符串转为_连接的
     * @param input 字符串
     */
    public static String camelCaseToUnderscore(String input) {
        if (input == null) {
            return null;
        }
 
        StringBuilder result = new StringBuilder();
        boolean prevIsLowerCase = false;
 
        for (char c : input.toCharArray()) {
            if (Character.isUpperCase(c)) {
                if (prevIsLowerCase) {
                    result.append('_');
                }
                result.append(Character.toLowerCase(c));
                prevIsLowerCase = false;
            } else {
                result.append(c);
                prevIsLowerCase = true;
            }
        }
 
        return result.toString();
    }
 
    /**
     * 字符串转16进制字符
     * @param input 字符串
     */
    public static String toHexString(String input) {
        StringBuilder str = new StringBuilder();
        for (int i = 0; i < input.length(); i++) {
            int ch = input.charAt(i);
            String s4 = Integer.toHexString(ch);
            str.append(s4);
        }
        return str.toString();
    }
}