worldbank / iefieldkit

Stata commands designed for Impact Evaluations field work. These are tools that are used during/after a survey in the field for data quality monitoring.
MIT License
38 stars 18 forks source link

General: Handling of special characters in locals #147

Open luizaandrade opened 4 years ago

luizaandrade commented 4 years ago

Luiza: Should probably find a way to keep these (special characters) in the future. Ben: Agree. At least it would be better to have a good list of what can and can't be handled well and what code conventions are needed to handle what characters.

_Originally posted by @luizaandrade in https://github.com/_render_node/MDIzOlB1bGxSZXF1ZXN0UmV2aWV3VGhyZWFkMjU5MjAzMzAxOnYy/pull_request_review_threads/discussion_

kbjarkefur commented 3 years ago

Add to utility functions

bbdaniels commented 3 years ago

@kbjarkefur here is what I typically do, for reference:

    // Clean up common characters
    foreach character in , . < > / [ ] | & ! ^ + - : = ( ) # "{" "}" "`" "'" {
      replace v1 = subinstr(v1,"`character'"," ",.)
    }
      replace v1 = subinstr(v1, char(34), "", .) // Remove " sign
      replace v1 = subinstr(v1, char(96), "", .) // Remove ` sign
      replace v1 = subinstr(v1, char(36), "", .) // Remove $ sign
      replace v1 = subinstr(v1, char(10), "", .) // Remove line end
kbjarkefur commented 3 years ago

@bbdaniels here is how you can modify locals without interpret them:

*Do not interpret macros
local line : subinstr local line "\$"  "\\$"
local line : subinstr local line "\`"  "\\`"

This code snippet comes from here.