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 /
This question was closed Feb 12, 2013 at 04:32 AM by sona.viswam for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by sona.viswam · Dec 21, 2012 at 12:58 AM · java

How to change a string into integer

I have to change s string to integer

 var floorname = coll.collider.gameObject.name;
    
 var cur = floorname.Substring(5);    
     
 var cu = parseInt(cur);


But while giving print(cu); it shows value. but with a error FormatException: Input string was not in the correct format System.Int32.Parse (System.String s)

How can i clear this?

Thanks in Advance

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

  • Sort: 
avatar image
3
Best Answer

Answer by kromenak · Dec 21, 2012 at 02:47 AM

This worked correctly for me when testing the following code:

 function Start()
 {
     var numberString = "12";
     var number = parseInt(numberString);
     print(number);
 }

However, if you change the "numberString" variable to some value that is not a number (like "foobar"), you get the exception you describe in your question.

It seems most likely that your "floorname.Substring" call is either not returning a string that represents a number, or it is returning a number with some extra characters, like "d12" or something. If you pass a string to parseInt that isn't actually a number, it seems to give this exception.

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 sona.viswam · Dec 21, 2012 at 03:46 AM 0
Share

@Clark $$anonymous$$romenaker :But sometimes it shows error.

avatar image aldonaletto · Dec 21, 2012 at 04:01 PM 0
Share

$$anonymous$$aybe floorname isn't what you expect in some cases. Add a debug line to show what caused the error:

 var cur = floorname.Substring(5);
 print("cur = "+ cur);

If you're getting floorname from some collision/trigger event, the error may occur when the object collides with another thing that doesn't have a "well behaved" name.

avatar image
1

Answer by sona.viswam · Dec 22, 2012 at 03:35 AM

Removed whitespaces by using

 cur = cur.Trim(); 

which works properly.

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

Follow this Question

Answers Answers and Comments

11 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

Related Questions

Mid point of a object 1 Answer

Mathf.pingpong 4 Answers

getting high score of game from asp.net page 2 Answers

,Roll a ball - project 0 Answers

FPS Controller rotate between two points c# 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