x


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);
}

    }


    }
more ▼

asked Nov 11 '11 at 10:08 PM

gtm1260 gravatar image

gtm1260
1 3 3 3

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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();
}
more ▼

answered Nov 11 '11 at 10:17 PM

DaveA gravatar image

DaveA
26.5k 151 171 256

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1951
x34
x28
x12
x7

asked: Nov 11 '11 at 10:08 PM

Seen: 915 times

Last Updated: Nov 11 '11 at 10:18 PM