// Copyright (c) 2003-2011, Jodd Team (jodd.org). All Rights Reserved.
package jodd.util;
import jodd.typeconverter.Convert;
import static jodd.util.StringPool.EMPTY;
import java.io.UnsupportedEncodingException;
/**
* Various String utilities.
* @see jodd.util.TextUtil
*/
public class StringUtil {
// ---------------------------------------------------------------- replace
/**
* Replaces all occurrences of a certain pattern in a string with a
* replacement string. This is the fastest replace function known to author.
*
* @param s string to be inspected
* @param sub string pattern to be replaced
* @param with string that should go where the pattern was
*/
public static String replace(String s, String sub, String with) {
int c = 0;
int i = s.indexOf(sub, c);
if (i == -1) {
return s;
}
int sLen = s.length();
StringBuilder buf = new StringBuilder(sLen + with.length());
do {
buf.append(s.substring(c,i));
buf.append(with);
c = i + sub.length();
} while ((i = s.indexOf(sub, c)) != -1);
if (c < sLen) {
buf.append(s.substring(c, sLen));
}
return buf.toString();
}
/**
* Replaces all occurrences of a character in a string.
*
* @param s input string
* @param sub character to replace
* @param with character to replace with
*/
public static String replaceChar(String s, char sub, char with) {
char[] str = s.toCharArray();
for (int i = 0; i < str.length; i++) {
if (str[i] == sub) {
str[i] = with;
}
}
return new String(str);
}
/**
* Replaces all occurrences of a characters in a string.
*
* @param s input string
* @param sub characters to replace
* @param with characters to replace with
*/
public static String replaceChars(String s, char[] sub, char[] with) {
char[] str = s.toCharArray();
for (int i = 0; i < str.length; i++) {
char c = str[i];
for (int j = 0; j < sub.length; j++) {
if (c == sub[j]) {
str[i] = with[j];
break;
}
}
}
return new String(str);
}
/**
* Replaces the very first occurrence of a substring with supplied string.
*
* @param s source string
* @param sub substring to replace
* @param with substring to replace with
*/
public static String replaceFirst(String s, String sub, String with) {
int i = s.indexOf(sub);
if (i == -1) {
return s;
}
return s.substring(0, i) + with + s.substring(i + sub.length());
}
/**
* Replaces the very first occurrence of a character in a string.
*
* @param s string
* @param sub char to replace
* @param with char to replace with
*/
public static String replaceFirst(String s, char sub, char with) {
char[] str = s.toCharArray();
for (int i = 0; i < str.length; i++) {
if (str[i] == sub) {
str[i] = with;
break;
}
}
return new String(str);
}
/**
* Replaces the very last occurrence of a substring with supplied string.
*
* @param s source string
* @param sub substring to replace
* @param with substring to replace with
*/
public static String replaceLast(String s, String sub, String with) {
int i = s.lastIndexOf(sub);
if (i == -1) {
return s;
}
return s.substring(0, i) + with + s.substring(i + sub.length());
}
/**
* Replaces the very last occurrence of a character in a string.
*
* @param s string
* @param sub char to replace
* @param with char to replace with
*/
public static String replaceLast(String s, char sub, char with) {
char[] str = s.toCharArray();
for (int i = str.length - 1; i >= 0; i--) {
if (str[i] == sub) {
str[i] = with;
break;
}
}
return new String(str);
}
// ---------------------------------------------------------------- remove
/**
* Removes all substring occurrences from the string.
*
* @param s source string
* @param sub substring to remove
*/
public static String remove(String s, String sub) {
int c = 0;
int sublen = sub.length();
if (sublen == 0) {
return s;
}
int i = s.indexOf(sub, c);
if (i == -1) {
return s;
}
StringBuilder buf = new StringBuilder(s.length());
do {
buf.append(s.substring(c, i));
c = i + sublen;
} while ((i = s.indexOf(sub, c)) != -1);
if (c < s.length()) {
buf.append(s.substring(c, s.length()));
}
return buf.toString();
}
/**
* Removes all characters contained in provided string.
*
* @param src source string
* @param chars string containing characters to remove
*/
public static String removeChars(String src, String chars) {
int i = src.length();
StringBuilder stringbuffer = new StringBuilder(i);
for (int j = 0; j < i; j++) {
char c = src.charAt(j);
if (chars.indexOf(c) == -1) {
stringbuffer.append(c);
}
}
return stringbuffer.toString();
}
/**
* Removes set of characters from string.
*
* @param src string
* @param chars characters to remove
*/
public static String removeChars(String src, char... chars) {
int i = src.length();
StringBuilder stringbuffer = new StringBuilder(i);
mainloop:
for (int j = 0; j < i; j++) {
char c = src.charAt(j);
for (char aChar : chars) {
if (c == aChar) {
continue mainloop;
}
}
stringbuffer.append(c);
}
return stringbuffer.toString();
}
/**
* Removes a single character from string.
*
* @param src source string
* @param chars character to remove
*/
public static String remove(String src, char chars) {
int i = src.length();
StringBuilder stringbuffer = new StringBuilder(i);
for (int j = 0; j < i; j++) {
char c = src.charAt(j);
if (c == chars) {
continue;
}
stringbuffer.append(c);
}
return stringbuffer.toString();
}
// ---------------------------------------------------------------- miscellaneous
/**
* Compares 2 strings. If one of the strings is <code>null</code>, <code>false</code> is returned. if
* both string are <code>null</code>, <code>true</code> is returned.
*
* @param s1 first string to compare
* @param s2 second string
*
* @return <code>true</code> if strings are equal, otherwise <code>false</code>
*/
public static boolean equals(String s1, String s2) {
return ObjectUtil.equals(s1, s2);
}
/**
* Determines if a string is empty (<code>null</code> or zero-length).
*/
public static boolean isEmpty(String string) {
return ((string == null) || (string.length() == 0));
}
/**
* Determines if string array contains empty strings.
* @see #isEmpty(String)
*/
public static boolean isAllEmpty(String... strings) {
for (String string : strings) {
if (isEmpty(string) == false) {
return false;
}
}
return true;
}
/**
* Determines if a string is blank (<code>null</code> or {@link #containsOnlyWhitespaces(String)}).
*/
public static boolean isBlank(String string) {
return ((string == null) || containsOnlyWhitespaces(string));
}
/**
* Determines if string is not blank.
*/
public static boolean isNotBlank(String string) {
return ((string != null) && !containsOnlyWhitespaces(string));
}
/**
* Determines if string array contains just blank strings.
*/
public static boolean isAllBlank(String... strings) {
for (String string : strings) {
if (isBlank(string) == false) {
return false;
}
}
return true;
}
/**
* Returns <code>true</code> if string contains only white spaces.
*/
public static boolean containsOnlyWhitespaces(String string) {
int size = string.length();
for (int i= 0; i < size; i++) {
char c = string.charAt(i);
if (CharUtil.isWhitespace(c) == false) {
return false;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
jodd java工具类库,包括数据库mvc依赖注入等等
共1879个文件
html:926个
java:881个
png:26个
5星 · 超过95%的资源 需积分: 50 43 下载量 184 浏览量
2011-08-30
23:07:08
上传
评论
收藏 9.07MB ZIP 举报
温馨提示
jodd java工具类库,包括数据库mvc依赖注入等等
资源推荐
资源详情
资源评论
收起资源包目录
jodd java工具类库,包括数据库mvc依赖注入等等 (1879个子文件)
jodd-wot.css 4KB
jodd.css 4KB
jodd-wot.css 4KB
jodd.css 4KB
sb.data 52B
file_id.diz 89B
inherit.gif 57B
inherit.gif 57B
index-all.html 1.14MB
index-all.html 844KB
JDateTime.html 150KB
ArraysUtil.html 141KB
StringUtil.html 131KB
DbOomQuery.html 129KB
constant-values.html 127KB
LoggablePreparedStatement.html 125KB
DbQuery.html 110KB
FileUtil.html 108KB
MimeTypes.html 85KB
DbProfiledQuery.html 68KB
Convert.html 67KB
constant-values.html 66KB
ReflectUtil.html 66KB
overview-tree.html 64KB
DbSqlBuilder.html 63KB
ServletUtil.html 62KB
overview-tree.html 59KB
DispatcherUtil.html 57KB
Printf.html 55KB
MethodSignatureVisitor.html 53KB
serialized-form.html 51KB
MadvocConfig.html 48KB
ClassDescriptor.html 48KB
ProxettaAsmUtil.html 47KB
JtxTransactionManager.html 46KB
DbOomManager.html 45KB
EmptyMethodVisitor.html 44KB
BeanUtil.html 44KB
FileNameUtil.html 43KB
PetiteRegistry.html 41KB
PetiteContainer.html 40KB
PetiteBeans.html 40KB
StringPool.html 40KB
TargetClassInfoReader.html 39KB
ClassFinder.html 39KB
ClassLoaderUtil.html 39KB
allclasses-frame.html 39KB
SqlChunk.html 39KB
allclasses-frame.html 38KB
SystemUtil.html 37KB
Email.html 36KB
StreamUtil.html 36KB
HashBag.html 36KB
MultipartRequest.html 35KB
TemplateData.html 34KB
Proxetta.html 34KB
ProxettaClassBuilder.html 33KB
allclasses-noframe.html 33KB
ReferenceMap.html 33KB
Props.html 33KB
JoddJspFunctions.html 33KB
CommonEmail.html 33KB
allclasses-noframe.html 32KB
JtxTransaction.html 32KB
IntHashMap.html 32KB
JulianDateStamp.html 31KB
DbEntitySql.html 31KB
TraceSignatureVisitor.html 30KB
ScopeDataResolver.html 30KB
JtxTransactionMode.html 29KB
AbstractCacheMap.html 29KB
FindFile.html 29KB
CoreConnectionPool.html 29KB
ProxyPointcutSupport.html 29KB
HtmlTag.html 29KB
ActionRequest.html 29KB
MadvocController.html 28KB
DefaultResultSetMapper.html 28KB
DateTimeStamp.html 28KB
CaddyDialog.html 28KB
PrintfFormat.html 28KB
RequestScopeInjector.Config.html 27KB
PetiteConfig.html 27KB
HtmlFormUtil.html 27KB
ActionMethodParser.html 27KB
AsmConsts.html 27KB
SortedArrayList.html 27KB
ActionsManager.html 27KB
CharUtil.html 27KB
ZipUtil.html 27KB
AnnotationTxAdviceManager.html 27KB
HashCode.html 26KB
ColumnsSelectChunk.html 26KB
ProxettaMethodBuilder.html 26KB
AdaptiveFileUpload.html 26KB
ReceivedEmail.html 26KB
InvokeReplacer.html 26KB
ResourceScanner.html 26KB
PropertiesUtil.html 25KB
AnnotationReader.html 25KB
共 1879 条
- 1
- 2
- 3
- 4
- 5
- 6
- 19
lineagezd
- 粉丝: 1
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页