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 james 6 · Mar 31, 2011 at 05:06 PM · textfilecsvio

parsing csv file

i have a csv file in my resource folder which i need to read, anybody know how to do it? i tried resource.load textasset but it didnt work. What is a good workaround to that?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by jahroy · Apr 22, 2011 at 09:07 PM

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

Then you can drag it 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 pieces separated by commas /

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 commas to process the data.

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 mthicke2 · Feb 11, 2013 at 08:41 AM 0
Share

I get this error: BCE0019: 'text' is not a member of 'System.Type'.

avatar image
1

Answer by Eric5h5 · Mar 31, 2011 at 08:18 PM

Any reason you have it in the Resources folder? Typically you'd just do:

var myTextFile : TextAsset;

as a public variable, then drag'n'drop.

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 junglemason · Oct 18, 2011 at 04:22 PM 0
Share

This works for $$anonymous$$onoBehaviours but not for singletons.

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

2 People are following this question.

avatar image avatar image

Related Questions

How to create and write a text file after compile/build 0 Answers

Create Text File 3 Answers

Write file after build 1 Answer

How can I get game data from a specified file? 0 Answers

Error copying PNG 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