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

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

问题描述

我可以使用这个:

String str = "TextX Xto modifyX";
str = str.replace('X','');//that does not work because there is no such character ''

有没有办法从Java中的字符串中删除所有出现的字符 X

Is there a way to remove all occurrences of character X from a String in Java?

我试过这个,不是我想要的: str.replace('X',''); //请替换为空格

I tried this and is not what I want: str.replace('X',' '); //replace with space

推荐答案

尝试使用重载,而不是 char :CharSequence arguments (例如 String p>

Try using the overload that takes CharSequence arguments (eg, String) rather than char:

str = str.replace("X", "");

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

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