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 h4wkeye · May 10, 2011 at 11:20 AM · javascriptparsing

reading a .csv file on a mac?

I made my dashboard and got everything done. now i want to read a .csv file with data like velocity, rpm, time etc and assign my dashboard's pointers to update after the values...

first things first, how can i actually read the file into unity and parse it properly ( a ";" is used to separate the values)

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Graham-Dunnett · May 10, 2011 at 11:48 AM

Rename the csv to txt and then use the Text Asset asset. See http://unity3d.com/support/documentation/Components/class-TextAsset.html. The text variable will give you access to the contents of this file, and you should be able to use string functions to break the string into the values you need. (I guess using javascripts string.split function.)

Comment
Add comment · Show 3 · Share
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 h4wkeye · May 10, 2011 at 11:52 AM 0
Share

thank you very much.

avatar image h4wkeye · May 10, 2011 at 12:11 PM 0
Share

i DO have another question though, when i want to actually use the values, how do i parse the file properly and access the values? i didn't find anything in the scripting reference

avatar image h4wkeye · May 10, 2011 at 12:41 PM 0
Share

sameless selfbumping rocks.

avatar image
0
Best Answer

Answer by h4wkeye · May 12, 2011 at 08:52 AM

Well i am able to print the string now, even after parsing it it still looks the same when i print it though. Code:

var TXT_data : TextAsset; var newline : String = "\n";

function Update() { var TXT_parsedArray; TXT_parsedArray = TXT_data.text; TXT_parsedArray.Split(newline[0]); print("File Content : " + TXT_parsedArray); }

Now i want to write each line into an array. help?^^

Comment
Add comment · Show 3 · Share
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 h4wkeye · May 12, 2011 at 10:27 AM 0
Share

selfbumping :/

avatar image h4wkeye · May 12, 2011 at 11:08 AM 0
Share

^ .

avatar image h4wkeye · May 12, 2011 at 11:41 AM 0
Share

come on guys :(

avatar image
1

Answer by jahroy · May 12, 2011 at 06:15 AM

You can create a TextAsset by dragging a text file into your project.

Then you can drag the TextAsset into the inspector to assign it to a public variable in your script:

/* public varialbe exposed in Inspector */

var myTextFile : TextAsset;

/ function that processes TextAsset /

function SomeFunction () {

/ split the contents of the file into an array of strings /

var stringArray = myTextFile.text.Split(";"[0]);

for ( var i = 0; i < stringArray.length; i ++ ) {

 print("I am element number " + i + ": " + stringArray[i]);  

}

}

The argument passed to the String.Split function is a hacky way of specifying a single character in UnityScript.

","[0] represents the 0th element of the one character String ",". As far as I know you can only use a character (not a String) to tokenize a string in Unity's version of Javascript.

In other words, it's something like this:

var theInputString = "Hello, world, I, like, commas...";

var theToken = ",";

var theArray = theInputString.Split(theToken[0]);

print(theArray.length);

/ output would be 5 /

You probably want to split your file by newline characters to process it line by line. Then you would split each line by semi-colons to process the data.

It might look something like this:

var newline : String = "\n"; var lineArray : String [] = myTextFile.text.Split(newline[0]);

var lineCount = 0;

for ( var thisLine : String in lineArray ) {

 var wordArray : String [] = thisLine.Split(";"[0]);

 lineCount ++;
 print("Line number: " + lineCount);

 var wordCount = 0;

 for ( var thisWord : String in wordArray ) {
     wordCount ++;
     print(" Word " + wordCount + ": " + thisWord);
 }

}

Comment
Add comment · Show 1 · Share
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 h4wkeye · May 12, 2011 at 07:26 AM 0
Share

Thanks :O looks well

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

No one has followed this question yet.

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

What is a good unityscript writing program? 1 Answer

converting "int" to "string" 2 Answers

editor script makes editor crash 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