How to I write native newline Characters (when using the systemCopyBuffer)?

I am writing an editor script using EditorGUIUtility.systemCopyBuffer to make a textual cut/paste for some custom data in my scene. My first intuition was that I could read and write to the system copy buffer on my own platform without having to worry about newline character differences. On Windows, my copied strings don't contain the correct windows newline sequence, " ", instead containing only the " " character.

I denote newline characters in my code with " ", but I expected that to either represent or be translated to the correct newline sequence for the environment (at least the one where initial compilation occurred). Perhaps this expectation comes incorrectly from a C++ mentality, but it is not fulfilled.

Ideally, there would be an easy way to get the proper newlines for the platform where Unity is being run.

What is the best way to fix my newline characters?

The .Net framework provides the System.Environment.NewLine property which will be the proper newline character sequence for the platform your program runs in. You can use " " as usual in your code and then translate back and fourth quickly by using something like this:

    myString = myString.Replace("
", System.Environment.NewLine);
    EditorGUIUtility.systemCopyBuffer = myString;