Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Create a quantity from composed quantities #937

Answered by angularsen
lenyturmel asked this question in Q&A
Discussion options

Hi all,

I have been reading your samples with a great interest but I am not sure that I could achieve my goals with this lib...

I have a quantity which is described by many values of differents units.
Could you please tell me how can I build the final quantity from all those parts ?

Example:
My volume described as:

  • 2 liters
  • 9 deciliters
  • 3 milliliters
    => the final quantity in liters should be 2,903 L

Thank you
Leny

You must be logged in to vote

Hi, there is no direct support for this in the library today.
The best you can accomplish today, is something like Volume.Parse("2 l") + Volume.Parse("9 dl") + Volume.Parse("3 ml").
Or similar with Volume.FromLiters(2) + .....

Replies: 1 comment 3 replies

Comment options

Hi, there is no direct support for this in the library today.
The best you can accomplish today, is something like Volume.Parse("2 l") + Volume.Parse("9 dl") + Volume.Parse("3 ml").
Or similar with Volume.FromLiters(2) + .....

You must be logged in to vote
3 replies
Comment options

thank you, that is a great solution for me

Comment options

I need a way to parse a string containing an enumeration of same quantity type (for example, "1 h 15 minute").

This could easily be achieved by parsing first "1 h" non greedily from "1 h 15 minute" and returning the number of char consumed (3). We could then iterate and check same quantity and different unit.

This could be usefull in configuration file.

Comment options

We actually had this in v3 (#81), and removed support for it in v4
#180 (comment)

It complicated the parsing code quite a bit, and there were some issues like
#343

Also, we realized the feature was mainly used for feet-inches at that time anyways, so it was removed as a generic implementation until.. I guess, until someone came asking for it, like now.

We kept the special parsing as its own method for feet-inches, so this does work:

Length.ParseFeetInches("2' 4\"")

I'm sure this could be revisited, but I still think it is a good idea to distinguish normal Parse() from parsing multiple quantities in the same string.

I don't have the time myself, but if you are interested in attempting a pull request I'm happy to assist.

Answer selected by lenyturmel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /