I want to use a StringBuilder to merge a couple of strings, and then give them to EditorGUIUtility.systemCopyBuffer in UnityEngine. One of the strings contains newline characters in itself, but they are not present when I paste the contents of the EditorGUIUtility.systemCopyBuffer. I cannot add the newline characters myself, as I don't know how many there are or where.
// This string is in my real code unknown to me.
// I also don't know the format of the newline characters.
string description = "A long description\nwith multiple lines.";
var builder = new StringBuilder();
builder.Append("Name: ");
builder.AppendLine(someObject.Name);
builder.Append("Description: ");
builder.AppendLine(description);
Debug.Log(builder.ToString());
EditorGUIUtility.systemCopyBuffer = builder.ToString();
The expected output, which is printed by Debug.Log in the Unity Console, is:
Name: A name
Description: A long description
with multiple lines.
So StringBuilder can handle it. But when I paste the text into e.g. notepad, it looks like this:
Name: A name
Description: A long descriptionwith multiple lines.
So the system copy buffer can handle the newlines that StringBuilder adds, but not the ones present in the original string. Can I make EditorGUIUtility.systemCopyBuffer include the newlines from the original string somehow?