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 AlucardJay · Jul 27, 2012 at 02:58 PM · stringsystem

parseInt a String not working

After parsering a text file into an array, I cannot typecast a value within from a string to an int. This usually works for me so I am clueless as to why this is breaking :

 //textureInfo.x = parseInt( _words[i + 3 + 2] );
 var valueX = ( _words[i + 3 + 2] ).ToString();
 textureInfo.x = parseInt( valueX );

Error :

FormatException: Input string was not in the correct format

System.Int32.Parse (System.String s)

UnityScript.Lang.UnityBuiltins.parseInt (System.String value)

Comment
Add comment · Show 1
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 AlucardJay · Jul 27, 2012 at 03:14 PM 0
Share

Thanks to both. It seems I am being bitten by the same *&^$% problem as in my other question : http://answers.unity3d.com/questions/291545/remove-tab-from-parsed-string.html

After running a test to check the length, it is showing one more character than I am expecting.

 Debug.Log( "_words[" + (i + 3 + 2) + "].Length " + _words[i + 3 + 2].Length );

Why is it I managed to write a reader for .fnt info files , but parsering a texpacker .json is giving me so much hassle ?

I am already cheating on the above question by using

 var newString = _word1;
 var index = newString.Length;
 if (index > 1)
 {
     newString = newString.Remove( 0, 1 );
 }

http://answers.unity3d.com/questions/291294/stringequals-not-working-as-expected.html

2 Replies

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

Answer by Bunny83 · Jul 27, 2012 at 03:08 PM

The error clearly says that the string you pass in is malformed / doesn't contain a number that can be converted. The first thing you should check is: What is in this string! Debug.Log might help.

Comment
Add comment · Show 2 · 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 AlucardJay · Jul 27, 2012 at 03:18 PM 0
Share

That is the answer to my question I think. When you posted this I was running a debug as it was the same thing in my other question. It's all stem$$anonymous$$g from the way the .json file is formatted (I'm fairly sure it's tabs that is throwing me off)

avatar image AlucardJay · Jul 27, 2012 at 03:49 PM 0
Share

Well I goofed up on this one. I hadn't removed the commas on this script. So thanks. Although my problem with tabs is still definitely valid : http://answers.unity3d.com/questions/291545/remove-tab-from-parsed-string.html

avatar image
0

Answer by Seth-Bergman · Jul 27, 2012 at 03:06 PM

try int.Parse :)

Comment
Add comment · Show 2 · 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 Bunny83 · Jul 27, 2012 at 03:09 PM 0
Share

parseInt maps to System.Int32.Parse as you can see in the exception above ;)

 System.Int32 == int
avatar image Seth-Bergman · Jul 27, 2012 at 03:13 PM 1
Share

sorry I meant int.TryParse maybe still not so useful tho..

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

7 People are following this question.

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

Related Questions

Extract number from string? 3 Answers

Why does SystemInfo.deviceUniqueIdentifier fail to return the same string? 0 Answers

Accessing local system ( File Browser ) 2 Answers

Is it possible for parseInt("5+5") to return 10? 2 Answers

parseInt givin' me issues! 2 Answers


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