Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
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
Add comment · 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 : $$anonymous$$onoBehaviour 
 {
     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 Found$$anonymous$$at;
     private bool Found$$anonymous$$odel;
     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 = "$$anonymous$$at_null";
         } 
         else if (y == 0) {
             price = "$$anonymous$$odel_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 = $$anonymous$$athf.$$anonymous$$ax(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.$$anonymous$$atch m in System.Text.RegularExpressions.Regex.$$anonymous$$atches(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.

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

Load external mp3 File without streaming 1 Answer

Can't play two audio with same clip by WWW 0 Answers

WWW can not load .tga file , is there any issue in WWW? 1 Answer

Webplayer crash on LoadImageIntoTexture call 1 Answer

the texture appear rubbish 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