Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

string to integer


  • Please log in to reply
2 replies to this topic

#1 Robert L.

Robert L.

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts

Posted 11 August 2011 - 01:37 AM

I needed to convert strings to integers, but it seems the built in functions for this are not available in 4.2, at least I could not seem to get them to work. Silly me if I just missed something. Anyway, assuming that they are missing, here is a bit of code that worked for me: public int Str2Int( string input ) { int ret = 0; // built the result here while (input.Length > 0) // stop when all chars have been processed { char c = input[0]; // get the first char if (c < '0') break; // stop if a non-number is found if (c > '9') break; int n = (int)c - 48; // ascii value to a number, IE '1' = 49 ret = n + 10 * ret; // accumulate the result input = input.Substring(1); // remove the first char } return ret; // return the result to caller } If someone else has a better way to go this, I would love to hear about it.

#2 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 11 August 2011 - 04:11 AM

You mean that int.Parse(string) is not working in the 4.2 release?
Biggest fault of Netduino? It runs by electricity.

#3 Robert L.

Robert L.

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts

Posted 11 August 2011 - 09:54 AM

You mean that int.Parse(string) is not working in the 4.2 release?


yes, at least I (in my befuddled state) was not able to get it working. It seemed to be missing as was the rest of System.Convert




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.