获取标签之间的子字符串
我读过一些关于按标签解析字符串的问题,但我没有找到我的具体问题的确切答案。 问题:我有一大行文本。我需要根据标签将此字符串解析为多个字符串。示例:我找到 [tag] 然后我读取文本直到 [tag] 并将其获取到一个新字符串。然后,我在出现相同的 [tag] 之前阅读文本,并将这些数据发布到新字符串,依此类推。
例子: [tag] Lorem Ipsum [tag] 只是印刷和排版行业的虚拟文本。自 1500 年代以来,Lorem Ipsum 一直是行业标准的虚拟文本,当时一位不知名的印刷商拿走了一堆字体并将其打乱以制作一本字体样本簿。 [tag] [tag]不仅生存了五个世纪,而且跨越了电子排版,基本保持不变。它在 20 世纪 60 年代随着包含 Lorem Ipsum 段落的 Letraset 表的发布而流行起来,最近又随着包含 Lorem Ipsum 版本的 Aldus PageMaker 等桌面出版软件而流行。
我想要基于此文本的三个字符串:Lorem Ipsum,它有,此文本之间的文本
I have read few questions about parsing string by tags, but I didn't find the exaact answer for my specific problem.
The Problem: I have a big line of text.I need to parse this string into multiple ones based on the tags. Exmaple: I find [tag] then I read the text until the [tag] and get it to a new string. Then I read the text before same [tag] appears, and post this data to a new string, and so on.
Example:
[tag] Lorem Ipsum [tag] is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. [tag] It has [tag] survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
I want three string based on this text: Lorem Ipsum, It has, text between this
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正则表达式来救援!
或者,您也可以手动浏览字符串。
Regular expressions to the rescue!
Alternatively you could just go through the String manually.
使用String类的split方法。它需要正则表达式作为参数:
Use split method of String class. It expects regular expression as a parameter: