首页>代码>javabean+servlet+jsp开发商品后台管理系统(源码+数据库脚本)>/JavaWebProject_v1.0/src/com/yueqian/project/common/StringTools.java
package com.yueqian.project.common;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringTools {
	private static Pattern linePattern = Pattern.compile("_(\\w)");
	private static Pattern humpPattern = Pattern.compile("[A-Z]");
	/**
	 * 驼峰转下划线,最后转为大写
	 * @param str
	 * @return
	 */
	public static String humpToLine(String str) {
	    Matcher matcher = humpPattern.matcher(str);
	    StringBuffer sb = new StringBuffer();
	    while (matcher.find()) {
	        matcher.appendReplacement(sb, "_" + matcher.group(0).toUpperCase());
	    }
	    matcher.appendTail(sb);
	    return sb.toString().toUpperCase();
	}

	/**
	 * 下划线转驼峰,正常输出
	 * @param str
	 * @return
	 */
	public static String lineToHump(String str) {
	    Matcher matcher = linePattern.matcher(str.toLowerCase());
	    StringBuffer sb = new StringBuffer();
	    while (matcher.find()) {
	        matcher.appendReplacement(sb, matcher.group(1).toUpperCase());
	    }
	    matcher.appendTail(sb);
	    return sb.toString();
	}
	
	/**
     * 处理null,将null的数据转为str
     * @param str
     * @return
     */
    public static String nullToStr(String str){
        if(str==null){
            return "";
        }
        return str;
    }
}
最近下载更多
穿山甲1001  LV6 2024年9月7日
TY0165  LV20 2024年6月18日
aholian  LV2 2024年6月13日
HangEcho  LV2 2024年6月5日
sz1111111  LV2 2024年3月26日
PSSDZH  LV3 2024年1月22日
aaasue  LV1 2024年1月4日
luoqingyun  LV1 2023年12月31日
玛莎纪  LV1 2023年12月26日
lanana  LV1 2023年12月22日
最近浏览更多
暂无贡献等级
wmmmmmm 前天
暂无贡献等级
歪比歪比 5月27日
暂无贡献等级
luoyun123 5月11日
暂无贡献等级
wwy000  LV2 4月29日
1138504729 4月13日
暂无贡献等级
wjnsfsdc 2月15日
暂无贡献等级
剩男与剩女 2024年12月12日
暂无贡献等级
Mhgfhjyrf  LV3 2024年12月8日
吴明艳 2024年11月25日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友