本文整理了Java中cn.hutool.core.util.StrUtil.removeSuffix()
方法的一些代码示例,展示了StrUtil.removeSuffix()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StrUtil.removeSuffix()
方法的具体详情如下:
包路径:cn.hutool.core.util.StrUtil
类名称:StrUtil
方法名:removeSuffix
[英]去掉指定后缀
[中]去掉指定后缀
代码示例来源:origin: looly/hutool
/**
* 去掉指定后缀,并小写首字母
*
* @param str 字符串
* @param suffix 后缀
* @return 切掉后的字符串,若后缀不是 suffix, 返回原字符串
*/
public static String removeSufAndLowerFirst(CharSequence str, CharSequence suffix) {
return lowerFirst(removeSuffix(str, suffix));
}
代码示例来源:origin: looly/hutool
/**
* 去掉指定后缀,并小写首字母
*
* @param str 字符串
* @param suffix 后缀
* @return 切掉后的字符串,若后缀不是 suffix, 返回原字符串
*/
public static String removeSufAndLowerFirst(CharSequence str, CharSequence suffix) {
return lowerFirst(removeSuffix(str, suffix));
}
代码示例来源:origin: looly/hutool
/**
* 根据用户引入的模板引擎jar,自动创建对应的模板引擎对象
*
* @param config 模板配置,包括编码、模板文件path等信息
* @return {@link Engine}
*/
public static TemplateEngine create(TemplateConfig config) {
final TemplateEngine engine = doCreate(config);
StaticLog.debug("Use [{}] Engine As Default.", StrUtil.removeSuffix(engine.getClass().getSimpleName(), "Engine"));
return engine;
}
代码示例来源:origin: looly/hutool
/**
* 根据用户引入的分词引擎jar,自动创建对应的分词引擎对象
*
* @return {@link TokenizerEngine}
*/
public static TokenizerEngine create() {
final TokenizerEngine engine = doCreate();
StaticLog.debug("Use [{}] Tokenizer Engine As Default.", StrUtil.removeSuffix(engine.getClass().getSimpleName(), "Engine"));
return engine;
}
代码示例来源:origin: looly/hutool
/**
* 根据用户引入的分词引擎jar,自动创建对应的分词引擎对象
*
* @return {@link TokenizerEngine}
*/
public static TokenizerEngine create() {
final TokenizerEngine engine = doCreate();
StaticLog.debug("Use [{}] Tokenizer Engine As Default.", StrUtil.removeSuffix(engine.getClass().getSimpleName(), "Engine"));
return engine;
}
代码示例来源:origin: looly/hutool
/**
* 根据用户引入的模板引擎jar,自动创建对应的模板引擎对象
*
* @param config 模板配置,包括编码、模板文件path等信息
* @return {@link Engine}
*/
public static TemplateEngine create(TemplateConfig config) {
final TemplateEngine engine = doCreate(config);
StaticLog.debug("Use [{}] Engine As Default.", StrUtil.removeSuffix(engine.getClass().getSimpleName(), "Engine"));
return engine;
}
代码示例来源:origin: stylefeng/Guns
@Override
protected void wrapTheMap(Map<String, Object> map) {
StringBuilder detail = new StringBuilder();
Long id = Long.valueOf(map.get("dictId").toString());
List<Dict> dicts = ConstantFactory.me().findInDict(id);
if (dicts != null) {
for (Dict dict : dicts) {
detail.append(dict.getCode()).append(":").append(dict.getName()).append(",");
}
map.put("detail", StrUtil.removeSuffix(detail.toString(), ","));
}
}
}
代码示例来源:origin: stylefeng/Guns
@Override
public List<Long> getParentDeptIds(Long deptId) {
Dept dept = deptMapper.selectById(deptId);
String pids = dept.getPids();
String[] split = pids.split(",");
ArrayList<Long> parentDeptIds = new ArrayList<>();
for (String s : split) {
parentDeptIds.add(Long.valueOf(StrUtil.removeSuffix(StrUtil.removePrefix(s, "["), "]")));
}
return parentDeptIds;
}
代码示例来源:origin: looly/hutool
/**
* 下载文件
*
* @param path 文件路径
* @param outFile 输出文件或目录
*/
@Override
public void download(String path, File outFile) {
final String fileName = FileUtil.getName(path);
final String dir = StrUtil.removeSuffix(path, fileName);
download(dir, fileName, outFile);
}
代码示例来源:origin: looly/hutool
/**
* 下载文件
*
* @param path 文件路径
* @param outFile 输出文件或目录
*/
@Override
public void download(String path, File outFile) {
final String fileName = FileUtil.getName(path);
final String dir = StrUtil.removeSuffix(path, fileName);
download(dir, fileName, outFile);
}
代码示例来源:origin: stylefeng/Guns
/**
* 解析一个组合字符串(例如: "1:启用;2:禁用;3:冻结" 这样的字符串)
*
* @author fengshuonan
* @Date 2017/4/27 16:44
*/
public static List<Map<String, String>> parseKeyValue(String mutiString) {
if (ToolUtil.isEmpty(mutiString)) {
return new ArrayList<>();
} else {
ArrayList<Map<String, String>> results = new ArrayList<>();
String[] items = StrUtil.split(StrUtil.removeSuffix(mutiString, ITEM_SPLIT), ITEM_SPLIT);
for (String item : items) {
String[] attrs = item.split(ATTR_SPLIT);
HashMap<String, String> itemMap = new HashMap<>();
itemMap.put(MUTI_STR_CODE, attrs[0]);
itemMap.put(MUTI_STR_NAME, attrs[1]);
itemMap.put(MUTI_STR_NUM, attrs[2]);
results.add(itemMap);
}
return results;
}
}
}
代码示例来源:origin: stylefeng/Guns
@Override
public String getMenuNames(String menuIds) {
Long[] menus = Convert.toLongArray(menuIds);
StringBuilder sb = new StringBuilder();
for (Long menu : menus) {
Menu menuObj = menuMapper.selectById(menu);
if (ToolUtil.isNotEmpty(menuObj) && ToolUtil.isNotEmpty(menuObj.getName())) {
sb.append(menuObj.getName()).append(",");
}
}
return StrUtil.removeSuffix(sb.toString(), ",");
}
代码示例来源:origin: looly/hutool
/**
* 文件或目录是否存在
*
* @param path 目录
* @return 是否存在
*/
public boolean exist(String path) {
final String fileName = FileUtil.getName(path);
final String dir = StrUtil.removeSuffix(path, fileName);
final List<String> names = ls(dir);
return containsIgnoreCase(names, fileName);
}
代码示例来源:origin: looly/hutool
/**
* 文件或目录是否存在
*
* @param path 目录
* @return 是否存在
*/
public boolean exist(String path) {
final String fileName = FileUtil.getName(path);
final String dir = StrUtil.removeSuffix(path, fileName);
final List<String> names = ls(dir);
return containsIgnoreCase(names, fileName);
}
代码示例来源:origin: stylefeng/Guns
return StrUtil.removeSuffix(sb.toString(), ",");
} else {
String fieldWarpperMethodName = dictMap.getFieldWarpperMethodName(key);
代码示例来源:origin: stylefeng/Guns
@Override
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.ROLES_NAME + "'+#roleIds")
public String getRoleName(String roleIds) {
if (ToolUtil.isEmpty(roleIds)) {
return "";
}
Long[] roles = Convert.toLongArray(roleIds);
StringBuilder sb = new StringBuilder();
for (Long role : roles) {
Role roleObj = roleMapper.selectById(role);
if (ToolUtil.isNotEmpty(roleObj) && ToolUtil.isNotEmpty(roleObj.getName())) {
sb.append(roleObj.getName()).append(",");
}
}
return StrUtil.removeSuffix(sb.toString(), ",");
}
代码示例来源:origin: looly/hutool
@Override
public boolean delFile(String path) {
final String pwd = pwd();
final String fileName = FileUtil.getName(path);
final String dir = StrUtil.removeSuffix(path, fileName);
cd(dir);
boolean isSuccess;
try {
isSuccess = client.deleteFile(fileName);
} catch (IOException e) {
throw new FtpException(e);
}
cd(pwd);
return isSuccess;
}
代码示例来源:origin: looly/hutool
@Override
public boolean delFile(String path) {
final String pwd = pwd();
final String fileName = FileUtil.getName(path);
final String dir = StrUtil.removeSuffix(path, fileName);
cd(dir);
boolean isSuccess;
try {
isSuccess = client.deleteFile(fileName);
} catch (IOException e) {
throw new FtpException(e);
}
cd(pwd);
return isSuccess;
}
代码示例来源:origin: looly/hutool
/**
* 获得相对子路径,忽略大小写
*
* 栗子:
*
* <pre>
* dirPath: d:/aaa/bbb filePath: d:/aaa/bbb/ccc =》 ccc
* dirPath: d:/Aaa/bbb filePath: d:/aaa/bbb/ccc.txt =》 ccc.txt
* dirPath: d:/Aaa/bbb filePath: d:/aaa/bbb/ =》 ""
* </pre>
*
* @param dirPath 父路径
* @param filePath 文件路径
* @return 相对子路径
*/
public static String subPath(String dirPath, String filePath) {
if (StrUtil.isNotEmpty(dirPath) && StrUtil.isNotEmpty(filePath)) {
dirPath = StrUtil.removeSuffix(normalize(dirPath), "/");
filePath = normalize(filePath);
final String result = StrUtil.removePrefixIgnoreCase(filePath, dirPath);
return StrUtil.removePrefix(result, "/");
}
return filePath;
}
代码示例来源:origin: looly/hutool
/**
* 获得相对子路径,忽略大小写
*
* 栗子:
*
* <pre>
* dirPath: d:/aaa/bbb filePath: d:/aaa/bbb/ccc =》 ccc
* dirPath: d:/Aaa/bbb filePath: d:/aaa/bbb/ccc.txt =》 ccc.txt
* dirPath: d:/Aaa/bbb filePath: d:/aaa/bbb/ =》 ""
* </pre>
*
* @param dirPath 父路径
* @param filePath 文件路径
* @return 相对子路径
*/
public static String subPath(String dirPath, String filePath) {
if (StrUtil.isNotEmpty(dirPath) && StrUtil.isNotEmpty(filePath)) {
dirPath = StrUtil.removeSuffix(normalize(dirPath), "/");
filePath = normalize(filePath);
final String result = StrUtil.removePrefixIgnoreCase(filePath, dirPath);
return StrUtil.removePrefix(result, "/");
}
return filePath;
}
内容来源于网络,如有侵权,请联系作者删除!