package com.horizon.common.util;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.text.StringCharacterIterator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.StringTokenizer;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
/**
* brief description.
* <p>
* Date :
* </p>
* <p>
* Module : 常用的字符串操作
* </p>
* <p>
* Description: 此类中封装一些常用的字符串操作 有方法都是静态方法,不需要生成此类的实例
* 为避免生成此类的实例,构造方法被申明为private类型
* </p>
* <p>
* Remark : 备注
* </p>
*
* @author
* @version 1.0
* <p>
* ------------------------------------------------------------
* </p>
* <p>
* 修改历史
* </p>
* <p>
* 序号 日期 修改 修改原因
* </p>
* <p>
* 1
* </p>
*/
public class StringUtil {
/**
* 私有构方法,防止类的实例化,因为工具类不要实例化.
*
*/
private StringUtil() {
}
/**
* 此方法将给出的字符串source使用delim划分为单词数�?.
*
*
* @param source
* 要进行划分的原字符串
* @param delim
* 单词的分隔字符串
* @return 划分以后的数组,如果source为null的时候返回以source为唯元素的数组, 如果delim为null则使用号作为分隔字符串
*
* @since 0.1
*/
public static String[] split(String source, String delim) {
String[] wordLists;
if (!isEmpty(source)) {
wordLists = new String[1];
wordLists[0] = source;
return wordLists;
}
if (delim == null) {
delim = ",";
}
StringTokenizer st = new StringTokenizer(source, delim);
int total = st.countTokens();
wordLists = new String[total];
for (int i = 0; i < total; i++) {
wordLists[i] = st.nextToken();
}
return wordLists;
}
/**
* 此方法将给出的字符串source使用delim划分为单词数�?.
*
*
* @param source
* 要进行划分的原字符串
* @param delim
* 单词的分隔字
*
* @return 划分以后的数组,如果source为null的时候返回以source为唯�?元素的数组�??
*
* @since 0.2
*/
public static String[] split(String source, char delim) {
return split(source, String.valueOf(delim));
}
/**
* 此方法将给出的字符串source使用逗号划分为单词数�?.
*
*
* @param source
* �?要进行划分的原字符串
* @return 划分以后的数组,如果source为null的时候返回以source为唯�?元素的数组�??
*
* @since 0.1
*/
public static String[] split(String source) {
return split(source, ",");
}
/**
* 以指定的字符和长度生成一个该字符的指定长度的字符�?.
*
*
* @param c
* 指定的字�?
*
* @param length
* 指定的长�?
*
* @return �?终生成的字符�?
*
* @since 0.6
*/
public static String fillString(char c, int length) {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < length; i++) {
buf.append(c);
}
return buf.toString();
}
/**
* 去除左边多余的空�?.
*
*
* @param value
* 待去左边空格的字符串
* @return 去掉左边空格后的字符�?
*
* @since 0.6
*/
public static String trimLeft(String value) {
String result = value;
if (result == null) {
return result;
}
char[] ch = result.toCharArray();
int index = -1;
for (int i = 0; i < ch.length; i++) {
if (Character.isWhitespace(ch[i])) {
index = i;
} else {
break;
}
}
if (index != -1) {
result = result.substring(index + 1);
}
return result;
}
/**
* 去除右边多余的空�?.
*
*
* @param value
* 待去右边空格的字符串
* @return 去掉右边空格后的字符�?
*
* @since 0.6
*/
public static String trimRight(String value) {
String result = value;
if (result == null) {
return result;
}
char[] ch = result.toCharArray();
int endIndex = -1;
for (int i = ch.length - 1; i > -1; i--) {
if (Character.isWhitespace(ch[i])) {
endIndex = i;
} else {
break;
}
}
if (endIndex != -1) {
result = result.substring(0, endIndex);
}
return result;
}
/**
* 根据转义列表对字符串进行转义.
*
*
* @param source
* 待转义的字符�?
*
* @param escapeCharMap
* 转义列表
* @return 转义后的字符�?
*
* @since 0.6
*/
public static String escapeCharacter(String source,
HashMap<?, ?> escapeCharMap) {
if (isEmpty(source)) {
return source;
}
if (escapeCharMap.size() == 0) {
return source;
}
StringBuffer sb = new StringBuffer();
StringCharacterIterator sci = new StringCharacterIterator(source);
for (char c = sci.first(); c != StringCharacterIterator.DONE; c = sci
.next()) {
String character = String.valueOf(c);
if (escapeCharMap.containsKey(character)) {
character = (String) escapeCharMap.get(character);
}
sb.append(character);
}
return sb.toString();
}
/**
* 得到字符串的字节长度.
*
*
* @param source
* 字符�?
*
* @return 字符串的字节长度
* @since 0.6
*/
public static int getByteLength(String source) {
int len = 0;
for (int i = 0; i < source.length(); i++) {
char c = source.charAt(i);
int highByte = c >>> 8;
len += highByte == 0 ? 1 : 2;
}
return len;
}
/**
* 得到字符串中的子串的个数.
*
*
* @param source
* 字符�?
*
* @param sub
* 子串
* @return 字符串中的子串的个数
* @since 0.6
*/
public static int getSubtringCount(String source, String sub) {
if (isEmpty(source)) {
return 0;
}
int count = 0;
int index = source.indexOf(sub);
while (index >= 0) {
count++;
index = source.indexOf(sub, index + 1);
}
return count;
}
/**
* 字符串判断为�?.
*
*
* @param string
* 字符�?
* @param nullretrun
* 子串
* @return 为null返回空串
* @since 0.6
*/
public static String getString(String string, String nullretrun) {
return StringUtils.isEmpty(string) ? nullretrun : string;
}
/**
* 字符串判断为�?.
*
*
* @param string
* 字符�?
*
* @param nullretrun
* 子串
* @return 为null返回空串,不为null返回字符串trim�?
* @since 0.6
*/
public static String getTrimString(String string, String nullretrun) {
return string == null ? nullretrun : string.trim();
}
/**
* 字符串转码,将ISO8859-1转化为UTF-8.
*
*
* @param str
* 字符�?
*
* @return 返回转码后字符串
* @throws UnsupportedEncodingException
* @since 0.6
*/
public static String transEncode(String str) {
String transStr = "";
try {
transStr = new String(getString(str, "").getBytes("ISO8859-1"),
"UTF-8");
} catch (UnsupportedEncodingException e) {
transStr = str;
}
return transStr;
}
/**
* 字符串不区分大小写,统一转换成大�?.
*
*
*
* @param str
* 字符�?
*
*
* @return 返回大写后字符串
* @throws UnsupportedEncodingException
* @since 0.6
*/
public static String stringChangeUpper(String str) {
if (!isEmpty(str)) {
str = str.toUpperCase();
} else {
str = "";
}
return str;
}
/**
* 方法�?要描述信�?.
* <p>
* 描述 : 关闭PrintWriter实例
* </p>
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
<项目介绍> 该资源内项目源码是个人的毕设,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 -------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
资源推荐
资源详情
资源评论
收起资源包目录
基于机器学习-音乐推荐系统+源代码+文档说明 (1106个子文件)
access_log.2018-01-25 0B
access_log.2019-12-22 14KB
access_log.2020-02-25 15KB
access_log.2020-02-27 10KB
access_log.2020-03-02 101KB
access_log.2020-03-05 138KB
access_log.2020-03-06 0B
access_log.2020-03-07 21KB
access_log.2020-03-08 9KB
access_log.2020-03-10 0B
access_log.2020-03-11 0B
access_log.2020-03-12 0B
access_log.2020-03-15 112KB
access_log.2020-03-16 63KB
access_log.2020-03-21 7KB
RedisClientDao.class 15KB
RedisClientDao.class 15KB
StringUtil.class 14KB
StringUtil.class 14KB
BaseDao.class 11KB
BaseDao.class 11KB
StationObserver.class 10KB
StationObserver.class 10KB
PileHsfVO.class 10KB
PileHsfVO.class 10KB
DateUtil.class 8KB
DateUtil.class 8KB
ReqEngine.class 8KB
ReqEngine.class 8KB
ObMessage.class 8KB
ObMessage.class 8KB
MechanismObserver.class 7KB
MechanismObserver.class 7KB
SqlBuilder.class 7KB
SqlBuilder.class 7KB
PileObserver.class 6KB
PileObserver.class 6KB
JsonIoConvertor.class 6KB
JsonIoConvertor.class 6KB
DCFaultEnum.class 5KB
DCFaultEnum.class 5KB
TaskSubmitMgrImpl.class 5KB
TaskSubmitMgrImpl.class 5KB
TreeUtil.class 5KB
TreeUtil.class 5KB
SysContextUtil.class 5KB
SysContextUtil.class 5KB
RedisUtli.class 4KB
RedisUtli.class 4KB
TreeNodeBean.class 4KB
TreeNodeBean.class 4KB
SocketClient.class 4KB
SocketClient.class 4KB
OrgLinksBox.class 4KB
OrgLinksBox.class 4KB
WebSocketUtil.class 4KB
WebSocketUtil.class 4KB
PileStatus.class 4KB
PileStatus.class 4KB
ACFaultEnum.class 3KB
ACFaultEnum.class 3KB
RedisMsgPubSubListener.class 3KB
RedisMsgPubSubListener.class 3KB
FaultTypeInfo.class 3KB
FaultTypeInfo.class 3KB
StationStatus.class 3KB
StationStatus.class 3KB
ArtistController.class 3KB
MechanismStatus.class 3KB
MechanismStatus.class 3KB
AlarmInfo.class 3KB
SysUserController.class 3KB
SysUserController.class 3KB
WorkOrderEnum.class 3KB
WorkOrderEnum.class 3KB
SysUserManagerServiceImpl.class 3KB
SysUserManagerServiceImpl.class 3KB
DateUtil$SysDate.class 3KB
DateUtil$SysDate.class 3KB
StationVO.class 3KB
StationVO.class 3KB
JsonUtil.class 3KB
JsonUtil.class 3KB
ArtistServiceImpl.class 2KB
ArtistController.class 2KB
Event.class 2KB
Event.class 2KB
ClusterDetailQuartzJobBean.class 2KB
ClusterDetailQuartzJobBean.class 2KB
DownloadUtil.class 2KB
DownloadUtil.class 2KB
ISDAO.class 2KB
ISDAO.class 2KB
ConstantsInfo.class 2KB
ConstantsInfo.class 2KB
OrgTreeVO.class 2KB
OrgTreeVO.class 2KB
PileConstantsInfo.class 2KB
PileConstantsInfo.class 2KB
ThreeDESUtil.class 2KB
共 1106 条
- 1
- 2
- 3
- 4
- 5
- 6
- 12
机智的程序员zero
- 粉丝: 1951
- 资源: 4199
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页