Search code examples
realbasicxojo

Xojo MacOs Vs. Windows? EndOFLine issue


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?


Solution

  • 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)