StringUtils

package com.example.springbootarbitrage.util;

import java.util.UUID;

/**
 * <p>Description: 字符串处理工具类</p>
 *
 * @author ccc
 * @date 2020/3/20 15:28
 * @since JDK1.8
 */
public final class StringUtils {

    /**
     * Generate a 32-bit primary key.
     * @return A randomly generated 32-bit primary key.
     */
    public static String UUID(){
        return  UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
    }
    /**
     * <p>
     * Checks if a String is empty ("") or null.
     * </p>
     *
     * <pre>
     * StringUtils.isEmpty(null)      = true
     * StringUtils.isEmpty("")        = true
     * StringUtils.isEmpty(" ")       = false
     * StringUtils.isEmpty("bob")     = false
     * StringUtils.isEmpty("  bob  ") = false
     * </pre>
     *
     * <p>
     * NOTE: This method changed in Lang version 2.0. It no longer trims the String. That functionality is available in isBlank().
     * </p>
     *
     * @param str the String to check, may be null
     * @return <code>true</code> if the String is empty or null
     */
    public static boolean isEmpty(String str) {
        return str == null || str.length() == 0;
    }

    /**
     * <p>
     * Checks if a String is whitespace, empty ("") or null.
     * </p>
     *
     * <pre>
     * StringUtils.isBlank(null)      = true
     * StringUtils.isBlank("")        = true
     * StringUtils.isBlank(" ")       = true
     * StringUtils.isBlank("bob")     = false
     * StringUtils.isBlank("  bob  ") = false
     * </pre>
     *
     * @param str the String to check, may be null
     * @return <code>true</code> if the String is null, empty or whitespace
     */
    public static boolean isBlank(String str) {
        int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return true;
        }
        for (int i = 0; i < strLen; i++) {
            if (!Character.isWhitespace(str.charAt(i))) {
                return false;
            }
        }
        return true;
    }

    /**
     * <p>
     * A string with any whitespace removed.
     * </p>
     *
     * @param str trimEnhance string
     * @return A string whose value is this string with any whitespace removed.
     */
    public static String trimEnhance(String str) {

        char[] charArray = str.toCharArray();
        int len = charArray.length;

        int st = 0;
        StringBuilder sb = new StringBuilder();
        while (st < len) {
            if (charArray[st] > ' ') sb.append(charArray[st]);
            st++;
        }
        return sb.toString();
    }

    /**
     * <p>
     * A string exclude one char.
     * </p>
     *
     * @param str excludeChar string
     * @param ch one char exclude
     * @return A string whose value is this string with any ch.
     */
    public static String excludeChar(String str,char ch){

        char[] charArray = str.toCharArray();
        int len = charArray.length;
        int st = 0;
        StringBuilder sb = new StringBuilder();
        while (st < len) {
            if (charArray[st]!=ch) sb.append(charArray[st]);
            st++;
        }
        return sb.toString();
    }

    /**
     * <p>
     * format all strings to numeric.
     * </p>
     *
     * @param str format string
     * @return A format string are numeric.
     */
    public static String findNumber(String str){

        char[] charArray = str.toCharArray();
        int len = charArray.length;
        int st = 0;

        StringBuilder sb = new StringBuilder();
        while (st < len) {
            //ASCII code  '0'-'9' 48-57
            if (charArray[st] >= '0' && charArray[st] <= '9') sb.append(charArray[st]);
            st++;
        }
        return sb.toString();
    }



}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值