mardi 12 janvier 2016

Do calculations on numbers in 1 multiline textView and return result replacing numbers

I am very new to android programming and am trying to complete my first app. It is a recipe converter.

I have stored my recipe details in a SQLite DB and the text for ingredients is just one multiline string separated by carriage returns. I have used a cursor to get the ingredient data into a textview which returns text like (could be numerous variants):

100ml Water 500 g Mince 2 x 400g can crushed tomatoes

etc.

I originally had each Qty, Unit and Ingredient Description stored separately in the database which made life easy when converting but I chose to store it in a multiline string to allow copying and pasting of ingredients from the internet or another source.

I am attempting to extract the numbers and then multiply them by a percentage, then return the new converted numbers, and the corresponding unit and description to get something like this:

(multiplied by 200%)

200ml Water 1000g Mince 4 x 400g can crushed tomatoes

I just don't know how to do it though. Can anyone help please?

Thanks

Aucun commentaire:

Enregistrer un commentaire