Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by DtBeloBrown · Apr 19, 2010 at 06:50 PM · editor-scriptingnewline

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, "\r\n", instead containing only the "\n" character.

I denote newline characters in my code with "\n", 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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by DtBeloBrown · Apr 19, 2010 at 06:51 PM

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 "\n" as usual in your code and then translate back and fourth quickly by using something like this:

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

See http://msdn.microsoft.com/en-us/library/system.environment.newline.aspx

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Cyclops · Apr 20, 2010 at 04:39 PM 0
Share

Good Question/Answer, I didn't know about that property. You must have pre-written the answer to beat @Duck to it, though :)

avatar image DtBeloBrown · Apr 20, 2010 at 05:38 PM 0
Share

hehe, I did indeed pre-write it. Duck is the speed machine. At first I thought it was a bug in systemCopyBuffer (I have come to expect non-native newlines popping up in a few strange places while using unity on windows), but once I figured out what was going on I figured it would still be worth sharing so I posted it anyway.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Scene Hierarchy Order logic? 1 Answer

NullReferenceException in UnityEditor.InspectorWindow.GetEditorsWithPreviews (UnityEditor.Editor[] editors) 0 Answers

Updating object on inspector value changes in editor 1 Answer

Creating graphs with nodes and edges in the editor (diagrams) 1 Answer

EditorWindow visibility 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges