1

So I created a program on Xojo(MacOS) that parses paragraphs using EndofLine. However, when I run it on a Windows operating system it doesn't parse it at all. Does Window operating systems recognize EndofLine or Chr(10)+Chr(13) in Xojo?

Ayah Al-Harthy
  • 103
  • 1
  • 9

2 Answers2

1

EndOfLine is always platform dependent, so in case of Windows, its value is chr(13)+chr(10), while on macOS it's chr(10). You can reach these platform-specific values directly by using EndOfLine.Windows and EndOfLine.OSX.

To normalise the line endings in a string, you can use the ReplaceLineEndings() function.

awagner
  • 58
  • 4
1

Xojo's EndOfLine constant is indeed different depending on the platform you use it for.

You have two choices of dealing with this:

Explicitly use a platform specific constant:

EndOfLine.Windows gives CR+LF
EndOfLine.Unix gives LF

The better way, especially if you import data from outside the program, e.g. when reading from a file or from a network socket, is to normalize the line delimiters for your internal use, like this:

normalizedString = ReplaceLineEndings (importedString, EndOfLine)

Now, you can use EndOfLine with normalizedString, e.g. to split it into single lines:

dim lines() as String = normalizedString.Split (EndOfLine)

When you write this string back, you'll automatically have it in the system's format already.

However, when you export your text to a system where you know it expects them in a certain format, convert them back to that format like this:

// E.g, if you export them for a Mac:
outputString = ReplaceLineEndings (internalString, EndOfLine.Unix)
Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149