如何从给定的String中删除子字符串? [英] How can I remove a substring from a given String?

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

问题描述

是否有一种简单的方法可以从Java中的给定String中删除子字符串?

Is there an easy way to remove substring from a given String in Java ?

示例:Hello World! ,删除o - >Hell Wrld!

example : "Hello World!" , removing "o" - > "Hell Wrld!"

推荐答案

您可以轻松使用 String.replace()

You could easily use String.replace():

String helloWorld = "Hello World!";
String hellWrld = helloWorld.replace("o","");

这篇关于如何从给定的String中删除子字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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