Actionscript string replacement and international currency.
This made me a little nostalgic for the olden days when a vacation to Europe was a remote possibility:
var str:String = "Now only $9.95!"; var price:RegExp = /\$([\d,]+.\d+)+/i; trace(str.replace(price, usdToEuro)); function usdToEuro(matchedSubstring:String, capturedMatch1:String, index:int, str:String):String { var usd:String = capturedMatch1; usd = usd.replace(",", ""); var exchangeRate:Number = 0.853690; var euro:Number = usd * exchangeRate; const euroSymbol:String = String.fromCharCode(8364); return euro.toFixed(2) + " " + euroSymbol; } |

The Actionscript string replacement and international currency. by Joel Hooks, unless otherwise expressly stated, is licensed under a Creative Commons Attribution 3.0 United States License.
Related posts:
- Enumerating data types in Actionscript 3 (AS3)
- Christian Cantrell’s ever-growing selection of useful Actionscript 3/AIR libraries.
- FlexUnit – Some useful examples and tutorials covering unit testing in Flex and Actionscript 3.0
- KitchenSync – open-source Actionscript 3 tweening and timing animation library
-
Kazuyoshi Tlacaelel














