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 Gringo02Kidsta · Dec 30, 2012 at 08:30 PM · stringintconvert

parseInt givin' me issues!

So I extract a string, by taking [string] input then .Remove(a,b)and remove part of the string, this leaves me with a string. Now I want to compare the left part of this string to an integer, eg. String: "Render 100" -> String: "100" -> ParseInt -> Int: 100

But upon entering "Render 100a" this results in an error, 100a cannot be parsed to int. How do I avoid this, possibly in the part where I compare the original string, and checks if it has an index of "Render".

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
0

Answer by jogo13 · Dec 30, 2012 at 09:42 PM

ParseInt cannot understand the 'a' at the end of '100a.' You'll need to remove it. (Why is it there?) //answer in comment below

Run it through your own 'preprocess' to create a string of only digits 0-9:

     string original_string;
     
     string number_string = "";
     
     for(int i = 0; i < original_string.Length; i++)
     {
       //continue this line from 0-9
       if(original_string[i] == '0' || original_string[i] == '1' || original_string[i] == '2'...)
          {
             //is a digit, add to string
             //is a char, need to convert to string
             number_string += original_string[i].ToString(); 
          }
       else //not a digit 
       {
           //do nothing for now
       }
      
     }
 
   //number_string should now be a string of only the numbers from the original_string
   //There's probably a more elegant way to do this :)
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 Gringo02Kidsta · Dec 30, 2012 at 10:27 PM 0
Share

No I realize that, but it's a consequence of user input, I can't remove the n'th ltter, since it might be 10, 10a, 100aaa.. Various output, I need a way to sort any int out of a string.

avatar image Owen-Reynolds · Dec 31, 2012 at 01:11 AM 0
Share

Can use char.isDigit( W[i] ) ins$$anonymous$$d of checking 0-9 by hand.

Code above would read "4a6b1c" as 461. To grab only continuous numbers, set sawNum=false;. When you see a number, set it true, so you know are reading digits. If sawNum=true and you don't see a number quit the loop (break.)

But, might be better to have the input method just reject letters (if you type one, it won't show up, like some internet forms.) Give the user faster feedback.

avatar image
0

Answer by Bunny83 · Dec 31, 2012 at 01:14 AM

https://www.google.com/#q=c%23+extract+number+string

  • first result -->

http://stackoverflow.com/questions/4734116/c-sharp-find-and-extract-number-from-a-string

edit

Or even just: that which gives me this:

http://answers.unity3d.com/questions/19053/extract-number-from-string.html

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 Lovrenc · Dec 31, 2012 at 01:35 AM 0
Share

I sometimes go google the answer to the questions posted here. Almost allways there are answers in 9/10 top links. $$anonymous$$any from unity answers itself. People don't even try no more.

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

12 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

Related Questions

Convert Array to String 3 Answers

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

Convert Text to float 3 Answers

Why Won't This Work? 1 Answer

js "Cannot convert 'String' to 'int'." error 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