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

Best way to convert string to number


  • Please log in to reply
6 replies to this topic

#1 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 25 April 2011 - 09:35 AM

What's the best way in NETMF to get (int)247 from (string)"247" ? Hope this question is clear ;) I want to convert a number that's in a string to an integer but haven't find a decent way so far.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#2 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 25 April 2011 - 10:17 AM

What's the best way in NETMF to get (int)247 from (string)"247" ?
Hope this question is clear ;) I want to convert a number that's in a string to an integer but haven't find a decent way so far.


Have you tried

int i = int.Parse(str);
Regards,
Mark

To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#3 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 25 April 2011 - 10:53 AM

Nope, was looking for something like that, thank you very much! :D
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#4 Michel Trahan

Michel Trahan

    Advanced Member

  • Members
  • PipPipPip
  • 155 posts

Posted 25 April 2011 - 03:28 PM

using System; ActualReading = Convert.ToUInt16(sActualReading);
Started with C in 1985, moved to Vb3 ... to vb6 and stopped. Now started with .Net and learning C# and VB.net and wishing VB.net was on MF !

#5 Eric Burdo

Eric Burdo

    Advanced Member

  • Members
  • PipPipPip
  • 130 posts

Posted 25 May 2011 - 12:52 AM

Does the .NETMF have the TryParse method?
~ Eric D. Burdo ~ http://brick-labs.com/

Today LED's, tomorrow, the world!!! Well, OK, maybe servos.

#6 Mati

Mati

    New Member

  • Members
  • Pip
  • 9 posts
  • LocationIsrael

Posted 30 May 2011 - 02:55 PM

Does the .NETMF have the TryParse method?


No it doesn't as far as I've seen. You should try/catch it if there's a chance that it's input
is not always numeric
Windows XP SP3, Q6600.

#7 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 30 May 2011 - 04:47 PM

You could also create the TryParse functionality by using the extension method features of C#. The base class needed to add extension method support has been posted to the forums...and I believe it is built into .NET MF 4.2 as well. Chris




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.