在 RealBasic 中将一段文本解析为适用于 Windows、Mac 和 Linux 的段落的最可靠方法是什么?

发布于 2024-12-01 14:40:34 字数 271 浏览 2 评论 0原文

我正在使用 RealBASIC 2011r3 编写一个软件,需要一种可靠的跨平台方法将字符串分解为段落。我一直在使用以下内容,但它似乎只适用于 Linux:

dim pTemp() as string
pTemp = Split(txtOriginalArticle.Text, EndOfLine + EndOfLine)

当我在 Mac 上尝试此操作时,它会将所有内容作为单个段落返回。使这项工作在 RB 支持的所有三个构建目标上可靠工作的最佳方法是什么?

I'm writing a piece of software using RealBASIC 2011r3 and need a reliable, cross-platform way to break a string out into paragraphs. I've been using the following but it only seems to work on Linux:

dim pTemp() as string
pTemp = Split(txtOriginalArticle.Text, EndOfLine + EndOfLine)

When I try this on my Mac it returns it all as a single paragraph. What's the best way to make this work reliably on all three build targets that RB supports?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

煞人兵器 2024-12-08 14:40:34

EndofLine 会根据平台以及创建字符串的平台而变化。您需要检查字符串中 EndOfLine 的类型。我相信它是 sMyString.EndOfLineType。一旦你知道它是什么,你就可以对其进行拆分。

EndOfLine 还有更多属性。它可以是 EndOfLine.Macintosh/Windows/Unix。

EndOfLine 文档: http://docs.realsoftware.com/index.php/EndOfLine

EndofLine changes depending upon platform and depending upon the platform that created the string. You'll need to check for the type of EndOfLine in the string. I believe it's sMyString.EndOfLineType. Once you know what it is you can then split on it.

There are further properties for the EndOfLine. It can be EndOfLine.Macintosh/Windows/Unix.

EndOfLine docs: http://docs.realsoftware.com/index.php/EndOfLine

左岸枫 2024-12-08 14:40:34

我几乎总是在继续之前搜索并替换换行符的组合。我通常会做几行:

yourString = ReplaceAll(yourString,chr(10)+chr(13),"")
yourString = ReplaceAll(yourString,chr(13)+chr(10),"")
yourString = ReplaceAll(yourString,chr(10),"")
yourString = ReplaceAll(yourString,chr(13),"")

这里的顺序很重要(在单个 10 之前执行 10+13),因为您不希望最终替换掉以下换行符:包含一个 10 和一个 13,以及两个换行支架。

这有点麻烦,我不建议使用它来实际修改原始字符串,但它肯定有助于在尝试进一步解析字符串之前将所有换行符转换为同一项目。

I almost always search for and replace the combinations of line break characters before continuing. I'll usually do a few lines of:

yourString = replaceAll(yourString,chr(10)+chr(13),"<someLineBreakHolderString>")
yourString = replaceAll(yourString,chr(13)+chr(10),"<someLineBreakHolderString>")
yourString = replaceAll(yourString,chr(10),"<someLineBreakHolderString>")
yourString = replaceAll(yourString,chr(13),"<someLineBreakHolderString>")

The order here matters (do 10+13 before an individual 10) because you don't want to end up replacing a line break that contains a 10 and a 13 with two of your line break holders.

It's a bit cumbersome and I wouldn't recommend using it to actually modify the original string, but it definitely helps to convert all of the line breaks to the same item before attempting to further parse the string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文