从字符串中删除所有出现的单词 [英] Remove all occurrences of a word from a string

查看:51
本文介绍了从字符串中删除所有出现的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下字符串

str="toto1 toto2 toto3 toto4 toto2 toto5"

to2 在字符串中出现两次.如何从字符串中删除所有 to2 项?

the toto2 occurs twice in the string. How can I remove all toto2 occurrences from the string?

我尝试过:

echo ${str/toto2/}

但这只会删除第一次出现的 toto2 .

But this will remove only the first occurrence of toto2.

toto1 toto3 toto4 toto2 toto5 # output

如何从字符串中删除所有 toto2 项?

How can I remove all toto2 occurrences from the string?

推荐答案

找到了它.解决方案是:

Found it. the solution is:

echo ${str//toto2/}

这篇关于从字符串中删除所有出现的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆