c# - Parsing pair of floats -


given string like: "0.123, 0.456" simplest way parse 2 float values 2 variables a , b?

i suggest:

  • split on comma (string.split)
  • trim (string.trim)
  • parse either float.parse or float.tryparse. (if want exception thrown if format incorrect, go parse. if want handle parsing failures part of normal control flow, use tryparse.)

if numbers going in format, explicitly specify cultureinfo.invariantculture. consider using decimal (or double) instead of float.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -