Created
November 25, 2021 12:55
-
-
Save KaiserWerk/22bd885dcc5351515da0c5364b24ede7 to your computer and use it in GitHub Desktop.
Add slashes to escape special 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
func Addslashes(str string) string { | |
var buf bytes.Buffer | |
for _, char := range str { | |
switch char { | |
case `'`, `"`, `\`: | |
buf.WriteRune(`\`) | |
} | |
buf.WriteRune(char) | |
} | |
return buf.String() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment