ReplaceLineEndings in New Framework: what is best way?

Do I have to know and search for all the possibilities (e.g. chr(10), chr(13), …)?
What is the easiest non-3rd-party way to do this?

ReplaceLineEndings

Notes

ReplaceLineEndings does a global search-and-replace for the end of line characters in SourceString using the specified line ending as the replacement string. The search automatically recognizes Windows, Macintosh, and Unix line endings. Use this function to make multiline (or multi-paragraph) text compatible across platforms. The easiest way to specify the replacement line ending is with the EndOfLine class.
Examples

This example replaces the line endings in the text in a TextField with Windows line endings.

Dim s as String
s=ReplaceLineEndings(TextField1.Text,EndOfLine.Windows)

or a better example… replace all line endings with the letter “X”

Dim s as String
s=ReplaceLineEndings(TextField1.Text,"X")

Thanks Dave,
I am familiar with this approach, but I am under the impression that moving to the new xojo framework, I should migrate code to work with TEXT rather than STRING data class, and I do not see a ReplaceLineEndings function for TEXT class. There is TEXT.ReplaceAll - which is fine, but it is not clear to me whether or not I need to search for multiple forms of EndOfLine characters.

In the documentation, I see this: Dim EOL As Text = Text.FromUnicodeCodepoint(10). And if this EOL character is all I need to find as line endings in TEXT domain, then great. But the questions is, do I also have to concern myself with Text.FromUnicodeCodepoint(13)? And are there others?

EndOfLine.Operator_Convert().ToText

I’m dreading the day when this is how we have to do stuff:

Dim EOL As Text = Text.FromUnicodeCodepoint(10)

How did we get to the point where
chr(10) turns into a novel?

&u0A is easier, no?

FYI, there are a variety of utilities for manipulating Text, including ReplaceLineEndings, in my M_Text module, available at:

http://www.mactechnologies.com/index.php?page=downloads#m_text

Here is how I solved it:

Protected Function ReplaceLineEndings(src As Text, other As Text) As Text
  const kCR as Text = &u0D
  const kLF as Text = &u0A
  const kCRLF as Text = &u0D + &u0A
  
  //
  // Normalize the line endings first
  //
  src = src.ReplaceAll( kCRLF, kLF )
  src = src.ReplaceAll( kCR, kLF )
  
  //
  // Now replace them
  //
  src = src.ReplaceAll( kLF, other )
  
  return src
  
End Function

So - is that the only line ending I need to think about when text is pasted into my programs from some unknown source, and all I want to do is act on line endings (e.g. to create a record for all text between line endings)? What about &u0D? Are there others?

[quote]How did we get to the point where
chr(10) turns into a novel?[/quote]

From my iOSWrapper :

Function chr(c as integer) As Text return Text.FromUnicodeCodepoint(c) End Function

https://github.com/Mitchboo/XojoiOSWrapper/tree/master

Mac standard was CR (&u0D), Unix and Mac current is LF (&u0A), and Windows is CR+LF. There are others, but they are not standard, e.g., LF+CR, and I’ve never encountered them in the “wild”.

You can also use the regular expression token “\R” to represent an EOL, but since the RegEx class is not yet part of the new framework and works only on strings, I didn’t mention it earlier.

Great info - thanks.

[quote=237034:@Jeff Tullin]I’m dreading the day when this is how we have to do stuff:

Dim EOL As Text = Text.FromUnicodeCodepoint(10)

How did we get to the point where
chr(10) turns into a novel?[/quote]
Using autocomplete makes it easy enough for me, plus with actually usable function names it’s clear what it does now.

[quote=237034:@Jeff Tullin]I’m dreading the day when this is how we have to do stuff:

Dim EOL As Text = Text.FromUnicodeCodepoint(10)

How did we get to the point where
chr(10) turns into a novel?[/quote]

We adopted Unicode where, thankfully, they made the conscious choice to make chr(10) mean the same as ASCII where that originated so many decades ago

But with “end of line” having at minimum 3 meanings in a cross platform toolset …

Just wait until they finally adopt klingon and I’m sure we’ll have yet another “end of line” code point

Doesn’t TextArea translate line endings for you? It seems like it used to, but that could be my faulty memory.