- Home /
 
Error when trying to parse csv file
I get a strange error when I try to take the data out of a csv file. I get : error CS1525: Unexpected symbol txt', expecting )', or `.' 
Here is my script
     using UnityEngine;
 using System.Collections;
 
 public class Mindthecube : MonoBehaviour {
 
     // Use this for initialization
     void Start () { FileInfo theSourceFile = null;
 TextReader reader = null;  // NOTE: TextReader, superclass of StreamReader and StringReader
  
 // Read from plain text file if it exists
 theSourceFile = new FileInfo (Application.dataPath + "/puzzles.txt");
 if ( theSourceFile != null && theSourceFile.Exists )
 {
    reader = theSourceFile.OpenText();  // returns StreamReader
 }
 else
 {
    // try to read from Resources instead
    TextAsset puzdata = (TextAsset)Resources.Load("puzzles", typeof(TextAsset));
    reader = new StringReader(puzdata.text);  // returns StringReader
 }
 if ( reader == null )
 {
    Debug.Log("puzzles.txt not found or not readable");
 }
 else
 {
    // Read each line from the file/resource
    while ( (string txt = reader.ReadLine()) != null )
    Debug.Log("-->" + txt);
 }
     
     }
     
 
     }
 
              
               Comment
              
 
               
              Answer by DaveA · Nov 11, 2011 at 10:17 PM
Try moving the declaration of 'txt' out of those parens, maybe it's getting scoped. Also you should indicate which line it's complaining on
 string txt;
 txt = reader.ReadLine();
 while (txt != null)
 {
   Debug.Log("-->"+txt);
   txt = reader.ReadLine();
 }
 
              Your answer
 
             Follow this Question
Related Questions
Getting parameter values sent to a method c sharp script 0 Answers
C# Script Haven't Check Box 2 Answers
Parsing a CSV load from server 1 Answer
C# script parse error 1 Answer
How do I fix the YAML error? 1 Answer