本文介绍了如何从Java中的特定字符串中删除特定字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,我要从文本文件中提取文本String,我需要这些词来形成数组.但是,当我执行所有这些操作时,有些单词以逗号(,)或句号(.)结尾,甚至在其上附加了括号(这完全是正常现象).
For example I'm extracting a text String from a text file and I need those words to form an array. However, when I do all that some words end with comma (,) or a full stop (.) or even have brackets attached to them (which is all perfectly normal).
我想做的就是摆脱那些角色.我一直在尝试使用Java中的预定义String方法来做到这一点,但我还是无法解决.
What I want to do is to get rid of those characters. I've been trying to do that using those predefined String methods in Java but I just can't get around it.
推荐答案
使用:
String str = "whatever";
str = str.replaceAll("[,.]", "");
replaceAll 使用正则表达式.这个:
[,.]
...查找每个逗号和/或句点.
...looks for each comma and/or period.
这篇关于如何从Java中的特定字符串中删除特定字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!