Created
January 11, 2016 17:58
-
-
Save JavaScript-Packer/3ab29f9fc3f92e032634 to your computer and use it in GitHub Desktop.
JavaScript function to swap 2 sets of strings with each other. Switch double quotes with single quotes for example. www.WHAK.ca
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
function swap_str(e, r, t) {//function to swap 2 sets of strings with each other | |
return e = e.split(r).join("WHAK_a_SWAP"), e = e.split(t).join("WHAK_b_SWAP"), e = e.split("WHAK_a_SWAP").join(t), | |
e = e.split("WHAK_b_SWAP").join(r); | |
} | |
//test 1 | |
var str = 'this is "test" of a \'test\' of swapping strings'; | |
var manipulated = swap_str(str,"'",'"'); | |
document.writeln(manipulated) | |
//test 2 | |
manipulated = swap_str(manipulated,"'",'"'); | |
document.writeln('<hr>'+manipulated) | |
//test 3 | |
manipulated = swap_str(manipulated,"test","of"); | |
document.writeln('<hr>'+manipulated) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment