Skip to content

Instantly share code, notes, and snippets.

@Gerst20051
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gerst20051/ccede851c8dfc8e9d168 to your computer and use it in GitHub Desktop.
Save Gerst20051/ccede851c8dfc8e9d168 to your computer and use it in GitHub Desktop.
Swift Strings Interpolation In JavaScript
// 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);
@Gerst20051
Copy link
Author

I've created a JSFiddle here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment