Groovy 字符流模式匹配
我有以下代码,从 reader
流中我想删除所有出现的 Command run successed.
请帮我建议任何解决方案
String ostream="license_all (47286) Command ran successfully. License a Command ran successfully."
Reader reader = new StringReader(ostream)
for(c in reader)
{
print(c)
}
I have the following code, from the reader
stream i want to remove all occurances of Command ran successfully.
Please help me suggest any solution
String ostream="license_all (47286) Command ran successfully. License a Command ran successfully."
Reader reader = new StringReader(ostream)
for(c in reader)
{
print(c)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只想要
Command run successed.
的精确形式,那么您可以这样做:但是,如果您想要更灵活,请忽略空格和大小写来替换它,使用这个:
注意,在这两种情况下,因为我们循环遍历每行,所以在换行符中重新添加可能很重要(
println
与打印
)。此外,由于在每一行上循环,如果字符串在多行上拆分,则不会替换该字符串。这是一个完整的示例,您可以运行和修改在 Groovy Web 控制台。 (使用
for...in
链接到原始链接。)If you only want the exact form of
Command ran successfully.
, then you can do this:However, if you want to be more flexible, and replace it disregarding spaces and case, use this:
Note, that in both instances, because we are looping over each line, it may be important to add back in the line break (
println
vsprint
). Also, due looping over each line, this will not replace the string if it occurs split on more than one line.Here's a complete example which you can run and modify on the Groovy Web Console. (Link to original one with
for...in
.)