Last active
August 29, 2015 14:18
-
-
Save Gerst20051/ccede851c8dfc8e9d168 to your computer and use it in GitHub Desktop.
Swift Strings Interpolation In JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://jsfiddle.net/gerst20051/zhzuwoqe/ | |
var language = 'swift'; | |
var how_awesome = 'very awesome!!'; | |
var string = 'hey i\'m a \\(language) string in disguise. \\(how_awesome)'; | |
function parseString(data) { | |
var re = /\\\((.*?)\)/g; | |
return data.replace(re, function(match) { | |
return eval(match.replace(/\\/g, '').replace(/\(/g, '').replace(/\)/g, '')); | |
}); | |
} | |
function log(data) { | |
alert(parseString(data)); | |
} | |
log(string); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've created a JSFiddle here.