
com.sghd.common.utils.StringUtil Maven / Gradle / Ivy
The newest version!
package com.sghd.common.utils;
import java.util.ArrayList;
public class StringUtil {
/***
* 修改String对象原有的split方法
*
* @param string
* @param split
* @return
*/
public static String[] split(String string, String split) {
int off = 0;
int next = 0;
ArrayList list = new ArrayList<>();
while ((next = string.indexOf(split, off)) != -1) {
list.add(string.substring(off, next));
off = next + 1;
}
// If no match was found, return this
if (off == 0)
return new String[] { string };
// Add remaining segment
list.add(string.substring(off, string.length()));
// Construct result
int resultSize = list.size();
String[] result = new String[resultSize];
return list.subList(0, resultSize).toArray(result);
}
public static int getWordCount(String content){
content = content.replaceAll("[^\\x00-\\xff]", "**");// 正则表达式,将汉字,全角替换成两个星号。
int length = content.length();
return length;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy