io - Unity C# Recognizing \n when reading in from text file -
I have a text file with several lines of string, for example "commander" and "44105" I'm going to show them on the screen. I need to create new lines at some points, but when I'm using \ n in the text file, the program does not recognize the new line, but \ N displays in the string when displayed in the string.
Reader = New Streamer ("Assets / Correct Entrepreneur. Txt", encoding. Default); While (! Reader. AndFirst & amp; Turnoff == Incorrect) {lineReader = Reader.ReadLine (); If (problemIndex == question index) {answer = lineReader; TurnOff = True; } Question Index + = 1; }
Everything else works well, it just does not recognize as a specific character. I would appreciate some help in getting this problem fixed.
OK, after the clarification, the question here is what can be done for you
list & lt; String & gt; Line = new list & lt; String & gt; (); (StreamReader Reader = New Stream Reader ("Assets / Test .txt")) using {string lines = reader.ReadToEnd (); Debug.Log (lines); Var splittext = lines.Split (new string [] {"|"}, // "\\ n" system in your case. StringSplitOptions.RemoveEmptyEntries); String result = string.api; Forchach (split in different data and endorsements) {string datatipers = data entree.trim (); Results + = DataTopers + Environment new line; } Debug. Logs (results); }
Please note that if you have a large file while trying to read, then ReadToEnd
can not work for you, but for example Will happen. Therefore, the reasoning here is to read the text file in a string, then use the split
method of the string that divides the initial string given by the delimiter and gives an array of strings, < Code> RemoveEmptyEntries means there will be no empty string in the resulting array. Now when you have got your identity identified, what can you do with them, in this case, we will not trim
them (hence no leading and finishing place) and we attach the data As a result, the new line (Please note that if you have a lot of data, then there will be better performance for using stringbilders to add results, because it gives more information Adding wire is more fast):
Before editing
When reading from a text file, the stream reader recognizes new lines and if you have text with some lines of text File, your method reads them correctly, but if you have a single line text file in "\ n" it will not be different from any two other characters, for example if you have a file In which there is a line:
"Text \ nmore text"
Your method line with only one string so that if you want you can manually \ n "parse the following string partition by parsing it And manually add new lines on your display string (I can help you if you want to achieve it).
But if I were you, then I save the data with only the standard new lines in the text file that will recognize the reader, for example you can do something like this:
list & lt; String & gt; DataToWrite = new list & lt; String & gt; () {"First line", "secondline", "third line"}; {Different characters in datatourite} {author.WriteLine (line) using the StreamWriter author = new streamer ("Asset / TestWrite. Txt")); //writer.write (line + environment. New line); //writer.Write (line + "\ r \ n"); }}
Note that the two rowed rows should also work for you, for more information about the new lines, you can check the following link:
< P>, is concerned :)
Comments
Post a Comment