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 /
  • Help Room /
avatar image
1
Question by eem · Aug 10, 2011 at 10:38 PM · stringparsegui.label

\n Not picked up when reading string from file's name

I have a bunch of images with various names. These images are loaded in, set as textures on a plane, then a script on each plane is set to hold the name of the file that the texture came from. I then am trying to display all these names via GUI.Label which works all just fine.

The only thing is, I wanted to have line breaks in some of the file names that are displayed via GUI.Label but when I put a \n into the filename, this doesn't come out as being an actual linebreak in the GUI.Label, instead the GUI.Label just shows \n.

Is there anyway to name a file with a \n in it, then read that file in, set a string equal to the file's.name, then when you display that string via GUI.Label have it actually use the \n to start a new line?

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
5
Best Answer

Answer by Owen-Reynolds · Aug 11, 2011 at 04:52 PM

'\n' for a linefeed only works for strings entered inside of a program (ex:string w="a\nb"; is 2 lines). In a text file or the Inspector you're normally expected to use the return key (in the Inspector the [TextArea] attribute allows multiple lines).

An old trick is to pick one char to stand for a linefeed, say $, then convert it into one later:

 fName=fName.Replace('$','\n'); // converts "clown city$part I" into two lines.


Any symbol works. Often you pick one you'd never normally use: @, *, and so on. Or, if you already have \n's everywhere, you use Replace to turn that into a real linefeed. This says to turn the 2 letters "slash" and "n" into the single thing '\n':

 fName=fName.Replace("\\n","\n");


Note that Replace doesn't change the string calling it. fName.Replace('$','\n'); does nothing. You have to catch the result using an =.

Comment
Add comment · Show 4 · 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 Jason B · Aug 11, 2011 at 06:05 PM 0
Share

Clown City? lol.

avatar image marjon4 · Aug 08, 2018 at 12:32 PM 0
Share

Tried everything but this $-trick was the only one that worked. Thanks!

avatar image unity_jSN6Q_iSu5g-0w · Nov 20, 2020 at 05:17 PM 0
Share

I'm using yarn spinner for interactive storytelling in my game and i couldn't find a way to break lines within yarn "lines" (to print multiple-line paragraphs in one block).

If anyone has the same issue, open DialogUI script of the yarn spinner. On line 287 use your own replace method on the "text" variable to break lines with your custom character and not go to the next line of the node.

avatar image unity_jSN6Q_iSu5g-0w · Nov 23, 2020 at 11:34 AM 0
Share

I love you @Owen-Reynolds. I was looking for this anwser for ages. Your description of the issue, why does it work in this way and your simple trick to solve it saved me. I'm using yarn spinner for interactive storytelling in my game and i couldn't find a way to break lines within yarn "lines" (to print multiple-line paragraphs in one block).

If anyone has the same issue, open DialogUI script of the yarn spinner on on the line 287 use your own replace method on the "text" variable to break lines with your custom character or even with "\n" wich will now work as line feed and not as "\" + "n".

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Error FormatException: Input string was not in a correct format. 0 Answers

Parse string value to add to enum List 2 Answers

I am getting this error when i try to parse a string to get float value. 0 Answers

Format Exception when trying to parseFloat(String) 2 Answers

Help int.Parse "Input String was not in the correct format" PROBLEM 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