![](/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.