如何打印文件中以条件字符串开头和结尾的某些行
我有一个这样的.txt文件:
[abc]
There is
a lot of
contents here
[abc]
[def]
Here are
many other
contents
[def]
[ghi]
and bunch of
contents here too
[ghi]
我想打印出标记字符串之间的内容,例如:打印出[abc]和[abc]之间的所有内容,而不打印出任何[abc]行。我怎样才能做到这一点?
I have a .txt file like this:
[abc]
There is
a lot of
contents here
[abc]
[def]
Here are
many other
contents
[def]
[ghi]
and bunch of
contents here too
[ghi]
I want to print out the contents between the tagged strings, for example: print out all the contents between [abc] and [abc], without printing out any [abc] line. How could I accomplish that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用布尔标志可以在简单的时间内完成
doable in a simple while with a boolean flag
使用 bufferedreader 和文件读取器进行输入。
循环输入行并使用 string.equals(string method) 来满足您的条件。
不为你写代码
Use bufferedreader and file reader for input.
loop through line of input and use the string.equals(string method) for your condition.
not writing code for you