从Java中的String中删除字符 [英] Remove characters from a String in Java
本文介绍了从Java中的String中删除字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用以下代码删除文件名的 .xml
部分:
I am trying to remove the .xml
part of a file name with the following code:
String id = fileR.getName();
id.replace(".xml", "");
idList.add(id);
问题是它没有删除它,我不知道为什么它不会删除它目标文本。
The problem is that it is not removing it and I have no clue why it won't remove the target text.
编辑 :实际上我意识到替换功能找不到。 xml
,所以我想问题是,如何摆脱最后4个字符?
EDIT: Actually I realize that the replace function won't find the .xml
, so I guess the question is, how do I get rid of those last 4 characters?
这是传入的字符串:
0b14d501a594442a01c6859541bcb3e8164d183d32937b851835442f69d5c94e.xml
谢谢,
推荐答案
字符串java是不可变的。这意味着您需要创建一个新字符串或覆盖旧字符串以实现所需的效果:
Strings in java are immutable. That means you need to create a new string or overwrite your old string to achieve the desired affect:
id = id.replace(".xml", "");
这篇关于从Java中的String中删除字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文