- Home /
Trying to get a text line to string from txt file
So I have a simple script that should draw text on GUI. I tried a couple of thing I found on the internet. My code looks okay but it gives the error "ArgumentException: path contains invalid characters"
here is a simplified part of my script:
public TextAsset theText;
string[] lines;
public Text subtitles;
void Start()
{
lines = System.IO.File.ReadAllLines(theTextEnglish.text);
subtitles.text = lines[52];
}
so I want to draw line 52 of the txt file I dragged and dropped in the inspector onto "theText"
What am I doing wrong exactly?
Answer by Z_Y_X · Jul 14, 2020 at 06:55 PM
Why you use public TextAsset theText and then theTextEnglish? if there are the same theText.text is a string text that is in the file.
System.IO.File.ReadAllLines require path. so you need to use:
lines = theText.text.Split('\n'); //\n is next line
subtitles.text = lines[52];
Thanks! I'll try this. And yea my mistake ^^' I was just simplifying my script here and copied a part but yea, originally in my script it says "theTextEnglish" but yea.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to make a Panel (Or Scrollbar) Appear on Button Click 0 Answers
I can't click to an UI button. 3 Answers
How to access a Text Mesh Pro Font Asset's glyp info from c#? 1 Answer