Bash处理字符串系列函数(三)
2023-04-18 12:36:02 时间
文章目录
反转字符串大小写
警告: 需要 bash
4+
示例函数:
reverse_case() {
# Usage: reverse_case "string"
printf '%s
' "${1~~}"
}
示例用法:
$ reverse_case "hello"
HELLO
$ reverse_case "HeLlO"
hElLo
$ reverse_case "HELLO"
hello
从字符串中删除引号
示例函数:
trim_quotes() {
# Usage: trim_quotes "string"
: "${1//'}"
printf '%s
' "${_//"}"
}
示例用法:
$ var="'Hello', "World""
$ trim_quotes "$var"
Hello, World
从字符串中删除模式的所有实例
示例函数:
strip_all() {
# Usage: strip_all "string" "pattern"
printf '%s
' "${1//$2}"
}
示例用法:
$ strip_all "The Quick Brown Fox" "[aeiou]"
Th Qck Brwn Fx
$ strip_all "The Quick Brown Fox" "[[:space:]]"
TheQuickBrownFox
$ strip_all "The Quick Brown Fox" "Quick "
The Brown Fox
相关文章
- 设计模式的征途—15.观察者(Observer)模式
- 设计模式的征途—14.职责链(Chain of Responsibility)模式
- 也看《我的前半生》:一辈子太长,我们只谈前半生
- 设计模式的征途—13.代理(Proxy)模式
- 设计模式的征途—12.享元(Flyweight)模式
- UML类图10分钟快速入门 - From 圣杰
- 浏览器是如何展示网页的
- Html,Css,Dom,javascript细节总结
- 设计模式的征途—10.装饰(Decorator)模式
- 浅谈背景图片的填充
- 设计模式的征途—8.桥接(Bridge)模式
- First Blog
- 我的2017OKR - 年中回顾
- 设计模式的征途—7.适配器(Adapter)模式
- 设计模式的征途—6.建造者(Builder)模式
- 设计模式的征途—5.原型(Prototype)模式
- 设计模式的征途—4.抽象工厂(Abstract Factory)模式
- 设计模式的征途—3.工厂方法(Factory Method)模式
- 设计模式的征途—2.简单工厂(Simple Factory)模式
- 《围城》读后感:你的心是一座城,愿你城中有幸福