• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by benfattino · Jun 29, 2015 at 12:35 PM · wwwloadcsv

load csv www

I need to load csv from www I try this:

 ...
 IEnumerator LoadCSV(){
 
                 WWW www = new WWW(url);
                 yield return www;
                 string str = www.text.ToString();
                 csvFile.text=str;
     }
 
     public void Start(){
             StartCoroutine (LoadCSV());
             grid = SplitCsvGrid(csvFile.text);
     
         }
 ...

I give me error message: Assets/CSVReaderWeb.cs(38,41): error CS0200: Property or indexer `UnityEngine.TextAsset.text' cannot be assigned to (it is read only)

Where I am wrong?

Comment

People who like this

0 Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image steakpinball · Jun 29, 2015 at 01:39 PM 0
Share

What type is csvFile? Can you post the declaration?

avatar image benfattino · Jun 29, 2015 at 01:53 PM 0
Share

This is the complete script:

 using UnityEngine;
 using System.Collections;
 using System.Linq; 
 using System.Text;
 using System.IO;
 
 public class CSVReaderWeb : MonoBehaviour 
 {
     public TextAsset csvFile; 
     public string csvText; 
     public string mat;
     public string model;
     public string price;
     int i ;
     int j;
     public int x;
     public int y;
     private bool FoundMat;
     private bool FoundModel;
     string[,] grid;
     public string url;
     
     public void Awake()
     {}

     IEnumerator LoadCSV(){
         WWW www = new WWW (url);
         yield return www;
         csvText = www.text;
     }
 
      public void Start(){
 
         StartCoroutine (LoadCSV());
         grid = SplitCsvGrid(csvFile.text);
     }
     
     public void Update (){
         x = 0;
         y = 0;
         for (int i = 0; i < grid.GetUpperBound(0); i++) {
             if (grid [i, 0] == mat) {
                 x = i;
             }
         }
         
         for (int j = 0; j < grid.GetUpperBound(1); j++) {
             if (grid [0, j] == model) {
                 y = j;
             }
         }
 
         if (x == 0) {
             price = "Mat_null";
         } 
         else if (y == 0) {
             price = "Model_null";
         }
         else {
             price = grid [x, y];
         }
         
         
     }
     
 
 
     
     // splits a CSV file into a 2D string array
     static public string[,] SplitCsvGrid(string csvText)
     {
         string[] lines = csvText.Split("\n"[0]); 
         
         // finds the max width of row
         int width = 0; 
         for (int i = 0; i < lines.Length; i++)
         {
             string[] row = SplitCsvLine( lines[i] ); 
             width = Mathf.Max(width, row.Length); 
         }
         
         // creates new 2D string grid to output to
         string[,] outputGrid = new string[width + 1, lines.Length + 1]; 
         for (int y = 0; y < lines.Length; y++)
         {
             string[] row = SplitCsvLine( lines[y] ); 
             for (int x = 0; x < row.Length; x++) 
             {
                 outputGrid[x,y] = row[x]; 
                 
                 // This line was to replace "" with " in my output. 
                 // Include or edit it as you wish.
                 outputGrid[x,y] = outputGrid[x,y].Replace("\"\"", "\"");
             }
         }
         
         return outputGrid; 
     }
     
     // splits a CSV row 
     static public string[] SplitCsvLine(string line)
     {
         return (from System.Text.RegularExpressions.Match m in System.Text.RegularExpressions.Regex.Matches(line,
                                                                                                             @"(((?<x>(?=[,\r\n]+))|""(?<x>([^""]|"""")+)""|(?<x>[^,\r\n]+)),?)", 
                                                                                                             System.Text.RegularExpressions.RegexOptions.ExplicitCapture)
                 select m.Groups[1].Value).ToArray();
     }
 }

I would only read the CSV file from URL. Thanks.

avatar image benfattino · Jun 29, 2015 at 03:31 PM 0
Share

public TextAsset csvFile;

I only need to load txt or csv file from www...

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I load texture files that are outside of my project folders? 1 Answer

load file with www on webplayer 1 Answer

Images don't load after building. 1 Answer

Loading a large texture at at run time kills fps 1 Answer

How to supress a # into a path string 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges