gpt4 book ai didi

bash - 在 bash shell 中用逗号删除字符串中的空格

转载 作者:行者123 更新时间:2023-11-29 08:51:53 25 4
gpt4 key购买 nike

我想用逗号替换字符串中的空格/空格。

STR1=This is a string 

STR1=This,is,a,string

最佳答案

不使用外部工具:

echo ${STR1// /,}

演示:

$ STR1="This is a string"
$ echo ${STR1// /,}
This,is,a,string

参见 bash: Manipulating strings .

关于bash - 在 bash shell 中用逗号删除字符串中的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9983566/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com