This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Arash Lowni
Posted Jun 09 - Read on Facebook

How do I parse substring from two strings and add them together?

e.g -

string1 = "£1.50"
string 2 = "£1.50"

add them together to get...

stringTotal = "£3.00"

Thanks.

5 Comments

Chris Camargo

Do you need to include £ in your first set of strings? If you need to perform arithmetic, I'd suggest using a function to transform your value (1.50) into a prepended string (£1.50), and do your math on the raw values.

Chris Camargo

But if you REALLY can't get around using formatting in your initial strings, here's an example. I just wouldn't recommend doing it this way. If your formatting changes in the future, you'd need to modify your logic for parsing the initial strings. http://share.framerjs.com/w7qoytm7jpir/

Jordan Robert Dobson

You could use regular expressions as well to remove the currency.

Thiago Duarte
Jordan Robert Dobson

Here's two options and a simple way to reformat it after you've added them together: http://jrdn.io/1T1Q2n2I2b3I

Read the entire post on Facebook