ReadRow() public method

Reads a row of columns from the current CSV file. Returns false if no more data could be read because the end of the file was reached.
public ReadRow ( List columns ) : bool
columns List Collection to hold the columns read
return bool
Exemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        if (news == null)
        {
            // load once
            TV04.news = new List <News>();
            TextAsset csv = Resources.Load(newsFile) as TextAsset;
            if (csv == null)
            {
                Debug.Assert(false);
                return;
            }

            using (var streamReader = new StreamReader(new MemoryStream(csv.bytes)))
            {
                using (var reader = new Mono.Csv.CsvFileReader(streamReader))
                {
                    // 0: id (N1)
                    // 1: article
                    List <string> row = new List <string>();
                    reader.ReadRow(row);                     // first row is header

                    // keep read content
                    while (reader.ReadRow(row))
                    {
                        var news = new News();
                        news.article = row[1];

                        TV04.news.Add(news);
                    }
                }
            }

            Debug.Log("news loaded");
        }

        var currentNews = news[VoteManager.currentVote.id - 1];

        transform.Find("Article").GetComponent <Text>().text = currentNews.article;
    }
Exemplo n.º 2
0
        public static bool TestWithRow(string inputFile, string outputFile)
        {
            using (var sr = new StreamReader (inputFile, Encoding.GetEncoding ("gbk"))) {
                var reader = new CsvFileReader (sr);
                using( var sw = new StreamWriter (outputFile, false, Encoding.GetEncoding ("gbk")) ) {
                    var writer = new CsvFileWriter(sw);

                    Console.WriteLine ("------------------------------------------------------------------------------");
                    var row = new List<string> ();
                    while (reader.ReadRow(row)) {
                        PrintRow(row);
                        writer.WriteRow( row );
                    }
                    Console.WriteLine ("------------------------------------------------------------------------------");
                }
            }

            return CompareFile (inputFile, outputFile);
        }