![](/img/trans.png)
[英]How to add both ints and strings from the same text file into different arrays Java
[英]Java: How to remove strings having the same prefix from a text file?
我需要替換文本文件中的一些字符串,例如“ upcoming:event = 123982”。
字符串始終以“ upcoming:event =“開頭。 如何刪除它們(包括數字)? (我正在用Java處理文本)。
我應該使用通配符嗎? 類似於“ upcoming:event = *”?
謝謝
String str = "upcoming:event=123982";
System.out.println(str.replaceFirst("upcoming:event=[0-9]*", "changed"));
輸出:已更改
String s="upcoming:event=123982;upcoming:event=100;upcoming:event=200;upcoming:event=900;upcoming:event=1987";
System.out.println(s.replaceAll("upcoming:event=[0-9]*", ""));
輸出:
123982;100;200;900;1987
即使這可能不是您可以使用的好方法
String text = "upcoming:event=*YOUR TEXT";
System.out.println(text.replace("upcoming:event=*", ""));
在這種情況下,結果將是您的文字...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.