problem retrieving data from csv file and arranging it in unity.

hiii im working lately in a project that needs to read a csv file and show the rows and not the columns, well you see most of the videos, tutorials and docs that i have found explains how to do it by reading the file and then showing just the columns like this example:

the file:

the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using System.IO;


public class UIOutputText : MonoBehaviour
{
    public List<operacion> operaciones = new List<operacion>();

     public Text cargo;
     public Text abono;
    void Start()
    {
        TextAsset datainfo = Resources.Load<TextAsset>("datainfo");
        string[] data = datainfo.text.Split(new char[] { '\n' });
        Debug.Log(data[1]);
        for (int i = 1; i < data.Length - 1; i++)
        {
            string[] row = data[i].Split(new char[] { ',' });
            operacion o = new operacion();
            o.data1 = row[0];
            o.data2 = row[1];
            o.data3 = row[2];
            o.data4 = row[3];

            operaciones.Add(o);

        }

        foreach (operacion o in operaciones)
        {
            Debug.Log(o.data2);
        }

    }

And the data is retrieved by columns and show in the debugger of unity like this:

[21:34:04] id
[21:34:04] data1
[21:34:04] data2

That’s good… but i don’t need that, now my case is something like this i have a csv file like this:

The file:

And it should be shown like this in unity (as a ui text file or in the debugger… you name it) :

sentencea worda sentenceg wordg

I don’t know how to do it, the only thing that i have is the code that is above and from there I don’t know how to proceed, is there any solution or advice… something? thanks in advance

Try searching in google with “parsing csv array site:forum.unity.com”
I’ve answered topics like this several times in the last couple of years and there are hundreds more.

Alright maybe i have searched the problem with the wrong choice of words… thanks :slight_smile:

You are combining two things:

  1. reading the source data (which just happens to be in CSV format)

  2. presentation of the data within Unity (perhaps using UnityEngine.UI components)

They have NOTHING to do with each other. DO NOT under any circumstances combine these two problems. They are utterly unrelated. Combining them will only trip you up.

Work on some tutorials until you can read CSV files into data structures inside of C#.

VERIFY that 100% of that process works by logging it out with Debug.Log()

Once you are fully comfortable that the data is coming in perfectly, then commit all that work to source control and move onto problem #2, presentation of the data.

This is not useful. “Showing how” is not the same as “learning how.” You need to do the latter.

Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

How to do tutorials properly, two (2) simple steps to success:

Tutorials are a GREAT idea. Tutorials should be used this way:

Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That’s how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.

Fortunately this is the easiest part to get right: Be a robot. Don’t make any mistakes.
BE PERFECT IN EVERYTHING YOU DO HERE!!

If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.

Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there’s an error, you will NEVER be the first guy to find it.

Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!

thanks, i will follow your advice and see what i got :slight_smile: