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

SAP Web Service from .NET via WCF -

Optimized Line drawing in QT -

datetime - str to time in python -