开发者

What's the most reliable way to parse a piece of text out into paragraphs in RealBasic that will work on Windows, Mac, and Linux?

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开发者_Python百科)

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?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜