Java:commons-lang3中的StringUtils.strip实现移除字符串首尾字符

依赖

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.12.0</version>
</dependency>

示例

// 包名
import org.apache.commons.lang3.StringUtils;

// 处理字符串,将首尾的花括号移除
String oldStr = "{[Hello,word]}";
String newStr = StringUtils.strip(oldStr, "{}");
System.out.println(newStr);
// [Hello,word]

参考

StringUtils.strip(String str, String stripChars)删除首尾指定的字符串

猜你喜欢

转载自blog.csdn.net/mouday/article/details/134929186
今日推荐