Created
October 1, 2018 19:07
-
-
Save jepras/0d6b9487e7f9f98f784dd8d537c20c50 to your computer and use it in GitHub Desktop.
Use switch to replace chars in a string. Use \ to escape characters.
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 convertHTML(str) { | |
var htmlStr = ""; | |
var search = function(char) { | |
switch (char) { | |
case '&': | |
console.log("& found"); | |
str = str.replace("&", "&"); | |
break; | |
case '<': | |
console.log("< found"); | |
str = str.replace("<", "<"); | |
break; | |
case '>': | |
console.log("> found"); | |
str = str.replace(">", ">"); | |
break; | |
case '\"': | |
console.log("double quotes found"); | |
str = str.replace("\"", """); | |
break; | |
case "'": | |
console.log("quote found"); | |
str = str.replace("'", "'"); | |
break; | |
} | |
} | |
for (var i = 0; i < str.length; i++) { | |
search(str[i]); | |
} | |
return str; | |
} | |
convertHTML("Schindler's List"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment