\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
into the filename, this doesn’t come out as being an actual linebreak in the GUI.Label, instead the GUI.Label just shows
.

Is there anyway to name a file with a
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
to start a new line?


’ for a linefeed only works for strings entered inside of a program (ex:string w="a b"; 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('$','

'); // 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
'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 ’
':

fName=fName.Replace("\

“,”
");

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

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 "
" wich will now work as line feed and not as "" + “n”.

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.