cn.hutool.core.util.StrUtil.subAfter()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(5.3k)|赞(0)|评价(0)|浏览(2150)

本文整理了Java中cn.hutool.core.util.StrUtil.subAfter()方法的一些代码示例,展示了StrUtil.subAfter()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StrUtil.subAfter()方法的具体详情如下:
包路径:cn.hutool.core.util.StrUtil
类名称:StrUtil
方法名:subAfter

StrUtil.subAfter介绍

[英]截取分隔字符串之后的字符串,不包括分隔字符串
如果给定的字符串为空串(null或""),返回原字符串
如果分隔字符串为空串(null或""),则返回空串,如果分隔字符串未找到,返回空串,举例如下:

StrUtil.subAfter(null, *)      = null 
StrUtil.subAfter("", *)        = "" 
StrUtil.subAfter("abc", 'a')   = "bc" 
StrUtil.subAfter("abcba", 'b') = "cba" 
StrUtil.subAfter("abc", 'c')   = "" 
StrUtil.subAfter("abc", 'd')   = ""

[中]截取分隔字符串之后的字符串,不包括分隔字符串
如果给定的字符串为空串(空)或""),返回原字符串
如果分隔字符串为空串(空)或""),则返回空串,如果分隔字符串未找到,返回空串,举例如下:

StrUtil.subAfter(null, *)      = null 
StrUtil.subAfter("", *)        = "" 
StrUtil.subAfter("abc", 'a')   = "bc" 
StrUtil.subAfter("abcba", 'b') = "cba" 
StrUtil.subAfter("abc", 'c')   = "" 
StrUtil.subAfter("abc", 'd')   = ""

代码示例

代码示例来源:origin: looly/hutool

/**
 * 从Content-Disposition头中获取文件名
 * @return 文件名,empty表示无
 */
private String getFileNameFromDisposition() {
  String fileName = null;
  final String desposition = header(Header.CONTENT_DISPOSITION);
  if(StrUtil.isNotBlank(desposition)) {
    fileName = ReUtil.get("filename=\"(.*?)\"", desposition, 1);
    if(StrUtil.isBlank(fileName)) {
      fileName = StrUtil.subAfter(desposition, "filename=", true);
    }
  }
  return fileName;
}
// ---------------------------------------------------------------- Private method end

代码示例来源:origin: looly/hutool

/**
 * 从Content-Disposition头中获取文件名
 * @return 文件名,empty表示无
 */
private String getFileNameFromDisposition() {
  String fileName = null;
  final String desposition = header(Header.CONTENT_DISPOSITION);
  if(StrUtil.isNotBlank(desposition)) {
    fileName = ReUtil.get("filename=\"(.*?)\"", desposition, 1);
    if(StrUtil.isBlank(fileName)) {
      fileName = StrUtil.subAfter(desposition, "filename=", true);
    }
  }
  return fileName;
}
// ---------------------------------------------------------------- Private method end

代码示例来源:origin: xkcoding/spring-boot-demo

/**
 * 在线用户分页列表
 *
 * @param pageCondition 分页参数
 * @return 在线用户分页列表
 */
public PageResult<OnlineUser> onlineUser(PageCondition pageCondition) {
  PageResult<String> keys = redisUtil.findKeysForPage(Consts.REDIS_JWT_KEY_PREFIX + Consts.SYMBOL_STAR, pageCondition.getCurrentPage(), pageCondition.getPageSize());
  List<String> rows = keys.getRows();
  Long total = keys.getTotal();
  // 根据 redis 中键获取用户名列表
  List<String> usernameList = rows.stream()
      .map(s -> StrUtil.subAfter(s, Consts.REDIS_JWT_KEY_PREFIX, true))
      .collect(Collectors.toList());
  // 根据用户名查询用户信息
  List<User> userList = userDao.findByUsernameIn(usernameList);
  // 封装在线用户信息
  List<OnlineUser> onlineUserList = Lists.newArrayList();
  userList.forEach(user -> onlineUserList.add(OnlineUser.create(user)));
  return new PageResult<>(onlineUserList, total);
}

代码示例来源:origin: cn.hutool/hutool-http

/**
 * 从Content-Disposition头中获取文件名
 * @return 文件名,empty表示无
 */
private String getFileNameFromDisposition() {
  String fileName = null;
  final String desposition = header(Header.CONTENT_DISPOSITION);
  if(StrUtil.isNotBlank(desposition)) {
    fileName = ReUtil.get("filename=\"(.*?)\"", desposition, 1);
    if(StrUtil.isBlank(fileName)) {
      fileName = StrUtil.subAfter(desposition, "filename=", true);
    }
  }
  return fileName;
}
// ---------------------------------------------------------------- Private method end

代码示例来源:origin: cn.hutool/hutool-all

/**
 * 从Content-Disposition头中获取文件名
 * @return 文件名,empty表示无
 */
private String getFileNameFromDisposition() {
  String fileName = null;
  final String desposition = header(Header.CONTENT_DISPOSITION);
  if(StrUtil.isNotBlank(desposition)) {
    fileName = ReUtil.get("filename=\"(.*?)\"", desposition, 1);
    if(StrUtil.isBlank(fileName)) {
      fileName = StrUtil.subAfter(desposition, "filename=", true);
    }
  }
  return fileName;
}
// ---------------------------------------------------------------- Private method end

代码示例来源:origin: xkcoding/spring-boot-demo

@PostMapping(value = "/local", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public Dict local(@RequestParam("file") MultipartFile file) {
  if (file.isEmpty()) {
    return Dict.create().set("code", 400).set("message", "文件内容为空");
  }
  String fileName = file.getOriginalFilename();
  String rawFileName = StrUtil.subBefore(fileName, ".", true);
  String fileType = StrUtil.subAfter(fileName, ".", true);
  String localFilePath = StrUtil.appendIfMissing(fileTempPath, "/") + rawFileName + "-" + DateUtil.current(false) + "." + fileType;
  try {
    file.transferTo(new File(localFilePath));
  } catch (IOException e) {
    log.error("【文件上传至本地】失败,绝对路径:{}", localFilePath);
    return Dict.create().set("code", 500).set("message", "文件上传失败");
  }
  log.info("【文件上传至本地】绝对路径:{}", localFilePath);
  return Dict.create().set("code", 200).set("message", "上传成功").set("data", Dict.create().set("fileName", fileName).set("filePath", localFilePath));
}

代码示例来源:origin: xkcoding/spring-boot-demo

String fileType = StrUtil.subAfter(fileName, ".", true);
String localFilePath = StrUtil.appendIfMissing(fileTempPath, "/") + rawFileName + "-" + DateUtil.current(false) + "." + fileType;
try {

相关文章

微信公众号

最新文章

更多

StrUtil类方法