本文整理了Java中cn.hutool.core.util.StrUtil.subSuf()
方法的一些代码示例,展示了StrUtil.subSuf()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StrUtil.subSuf()
方法的具体详情如下:
包路径:cn.hutool.core.util.StrUtil
类名称:StrUtil
方法名:subSuf
[英]切割指定位置之后部分的字符串
[中]切割指定位置之后部分的字符串
代码示例来源:origin: looly/hutool
/**
* 小写首字母<br>
* 例如:str = Name, return name
*
* @param str 字符串
* @return 字符串
*/
public static String lowerFirst(CharSequence str) {
if (null == str) {
return null;
}
if (str.length() > 0) {
char firstChar = str.charAt(0);
if (Character.isUpperCase(firstChar)) {
return Character.toLowerCase(firstChar) + subSuf(str, 1);
}
}
return str.toString();
}
代码示例来源:origin: looly/hutool
/**
* 大写首字母<br>
* 例如:str = name, return Name
*
* @param str 字符串
* @return 字符串
*/
public static String upperFirst(CharSequence str) {
if (null == str) {
return null;
}
if (str.length() > 0) {
char firstChar = str.charAt(0);
if (Character.isLowerCase(firstChar)) {
return Character.toUpperCase(firstChar) + subSuf(str, 1);
}
}
return str.toString();
}
代码示例来源:origin: looly/hutool
/**
* 小写首字母<br>
* 例如:str = Name, return name
*
* @param str 字符串
* @return 字符串
*/
public static String lowerFirst(CharSequence str) {
if (null == str) {
return null;
}
if (str.length() > 0) {
char firstChar = str.charAt(0);
if (Character.isUpperCase(firstChar)) {
return Character.toLowerCase(firstChar) + subSuf(str, 1);
}
}
return str.toString();
}
代码示例来源:origin: looly/hutool
/**
* 大写首字母<br>
* 例如:str = name, return Name
*
* @param str 字符串
* @return 字符串
*/
public static String upperFirst(CharSequence str) {
if (null == str) {
return null;
}
if (str.length() > 0) {
char firstChar = str.charAt(0);
if (Character.isLowerCase(firstChar)) {
return Character.toUpperCase(firstChar) + subSuf(str, 1);
}
}
return str.toString();
}
代码示例来源:origin: looly/hutool
/**
* 忽略大小写去掉指定前缀
*
* @param str 字符串
* @param prefix 前缀
* @return 切掉后的字符串,若前缀不是 prefix, 返回原字符串
*/
public static String removePrefixIgnoreCase(CharSequence str, CharSequence prefix) {
if (isEmpty(str) || isEmpty(prefix)) {
return str(str);
}
final String str2 = str.toString();
if (str2.toLowerCase().startsWith(prefix.toString().toLowerCase())) {
return subSuf(str2, prefix.length());// 截取后半段
}
return str2;
}
代码示例来源:origin: looly/hutool
/**
* 获取用于密钥生成的算法<br>
* 获取XXXwithXXX算法的后半部分算法,如果为ECDSA或SM2,返回算法为EC
*
* @param algorithm XXXwithXXX算法
* @return 算法
*/
public static String getAlgorithmAfterWith(String algorithm) {
Assert.notNull(algorithm, "algorithm must be not null !");
int indexOfWith = StrUtil.lastIndexOfIgnoreCase(algorithm, "with");
if (indexOfWith > 0) {
algorithm = StrUtil.subSuf(algorithm, indexOfWith + "with".length());
}
if ("ECDSA".equalsIgnoreCase(algorithm) || "SM2".equalsIgnoreCase(algorithm)) {
algorithm = "EC";
}
return algorithm;
}
代码示例来源:origin: looly/hutool
/**
* 获取用于密钥生成的算法<br>
* 获取XXXwithXXX算法的后半部分算法,如果为ECDSA或SM2,返回算法为EC
*
* @param algorithm XXXwithXXX算法
* @return 算法
*/
public static String getAlgorithmAfterWith(String algorithm) {
Assert.notNull(algorithm, "algorithm must be not null !");
int indexOfWith = StrUtil.lastIndexOfIgnoreCase(algorithm, "with");
if (indexOfWith > 0) {
algorithm = StrUtil.subSuf(algorithm, indexOfWith + "with".length());
}
if ("ECDSA".equalsIgnoreCase(algorithm) || "SM2".equalsIgnoreCase(algorithm)) {
algorithm = "EC";
}
return algorithm;
}
代码示例来源:origin: looly/hutool
/**
* 忽略大小写去掉指定前缀
*
* @param str 字符串
* @param prefix 前缀
* @return 切掉后的字符串,若前缀不是 prefix, 返回原字符串
*/
public static String removePrefixIgnoreCase(CharSequence str, CharSequence prefix) {
if (isEmpty(str) || isEmpty(prefix)) {
return str(str);
}
final String str2 = str.toString();
if (str2.toLowerCase().startsWith(prefix.toString().toLowerCase())) {
return subSuf(str2, prefix.length());// 截取后半段
}
return str2;
}
代码示例来源:origin: looly/hutool
/**
* 去掉指定前缀
*
* @param str 字符串
* @param prefix 前缀
* @return 切掉后的字符串,若前缀不是 preffix, 返回原字符串
*/
public static String removePrefix(CharSequence str, CharSequence prefix) {
if (isEmpty(str) || isEmpty(prefix)) {
return str(str);
}
final String str2 = str.toString();
if (str2.startsWith(prefix.toString())) {
return subSuf(str2, prefix.length());// 截取后半段
}
return str2;
}
代码示例来源:origin: looly/hutool
/**
* 去掉指定前缀
*
* @param str 字符串
* @param prefix 前缀
* @return 切掉后的字符串,若前缀不是 preffix, 返回原字符串
*/
public static String removePrefix(CharSequence str, CharSequence prefix) {
if (isEmpty(str) || isEmpty(prefix)) {
return str(str);
}
final String str2 = str.toString();
if (str2.startsWith(prefix.toString())) {
return subSuf(str2, prefix.length());// 截取后半段
}
return str2;
}
代码示例来源:origin: looly/hutool
if(sepIndex > 0) {
pre = StrUtil.subPre(url, sepIndex + 3);
body = StrUtil.subSuf(url, sepIndex + 3);
}else {
pre = "http://";
String params = null;
if(paramsSepIndex > 0) {
params = StrUtil.subSuf(body, paramsSepIndex);
body = StrUtil.subPre(body, paramsSepIndex);
代码示例来源:origin: looly/hutool
paramsStr = StrUtil.subSuf(paramsStr, pathEndPos + 1);
代码示例来源:origin: looly/hutool
if(sepIndex > 0) {
pre = StrUtil.subPre(url, sepIndex + 3);
body = StrUtil.subSuf(url, sepIndex + 3);
}else {
pre = "http://";
String params = null;
if(paramsSepIndex > 0) {
params = StrUtil.subSuf(body, paramsSepIndex);
body = StrUtil.subPre(body, paramsSepIndex);
代码示例来源:origin: looly/hutool
paramsStr = StrUtil.subSuf(paramsStr, pathEndPos + 1);
代码示例来源:origin: looly/hutool
/**
* 如果某些值为null,使用默认值
*
* @return this
*/
public MailAccount defaultIfEmpty() {
// 去掉发件人的姓名部分
final String fromAddress = InternalMailUtil.parseFirstAddress(this.from, this.charset).getAddress();
if (StrUtil.isBlank(this.host)) {
// 如果SMTP地址为空,默认使用smtp.<发件人邮箱后缀>
this.host = StrUtil.format("smtp.{}", StrUtil.subSuf(fromAddress, fromAddress.indexOf('@') + 1));
}
if (StrUtil.isBlank(user)) {
// 如果用户名为空,默认为发件人邮箱前缀
this.user = StrUtil.subPre(fromAddress, fromAddress.indexOf('@'));
}
if (null == this.auth) {
// 如果密码非空白,则使用认证模式
this.auth = (false == StrUtil.isBlank(this.pass));
}
if (null == this.port) {
// 端口在SSL状态下默认与socketFactoryPort一致,非SSL状态下默认为25
this.port = (null != this.sslEnable && this.sslEnable) ? this.socketFactoryPort : 25;
}
if (null == this.charset) {
// 默认UTF-8编码
this.charset = CharsetUtil.CHARSET_UTF_8;
}
return this;
}
代码示例来源:origin: looly/hutool
/**
* 如果某些值为null,使用默认值
*
* @return this
*/
public MailAccount defaultIfEmpty() {
// 去掉发件人的姓名部分
final String fromAddress = InternalMailUtil.parseFirstAddress(this.from, this.charset).getAddress();
if (StrUtil.isBlank(this.host)) {
// 如果SMTP地址为空,默认使用smtp.<发件人邮箱后缀>
this.host = StrUtil.format("smtp.{}", StrUtil.subSuf(fromAddress, fromAddress.indexOf('@') + 1));
}
if (StrUtil.isBlank(user)) {
// 如果用户名为空,默认为发件人邮箱前缀
this.user = StrUtil.subPre(fromAddress, fromAddress.indexOf('@'));
}
if (null == this.auth) {
// 如果密码非空白,则使用认证模式
this.auth = (false == StrUtil.isBlank(this.pass));
}
if (null == this.port) {
// 端口在SSL状态下默认与socketFactoryPort一致,非SSL状态下默认为25
this.port = (null != this.sslEnable && this.sslEnable) ? this.socketFactoryPort : 25;
}
if (null == this.charset) {
// 默认UTF-8编码
this.charset = CharsetUtil.CHARSET_UTF_8;
}
return this;
}
代码示例来源:origin: looly/hutool
final String path = this.httpConnection.getUrl().getPath();
fileName = StrUtil.subSuf(path, path.lastIndexOf('/') + 1);
if (StrUtil.isBlank(fileName)) {
代码示例来源:origin: looly/hutool
final String path = this.httpConnection.getUrl().getPath();
fileName = StrUtil.subSuf(path, path.lastIndexOf('/') + 1);
if (StrUtil.isBlank(fileName)) {
代码示例来源:origin: looly/hutool
paramPart = StrUtil.subSuf(paramsStr, pathEndPos + 1);
if (StrUtil.isBlank(paramPart)) {
代码示例来源:origin: looly/hutool
paramPart = StrUtil.subSuf(paramsStr, pathEndPos + 1);
if (StrUtil.isBlank(paramPart)) {
内容来源于网络,如有侵权,请联系作者删除!