15Jan/081
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 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.
-
Kazuyoshi Tlacaelel















