Easy substring removal
I want to use ion to parse a config that looks like this, where the unique name given before the underscore _
is treated as part of a set.
HOST1_USERFILE=cloud-config/one.yml
HOST1_OS=ubuntu_18_04
HOST1_FACILITY=sjc1
HOST2_USERFILE=cloud-config/two.yml
HOST2_OS=ubuntu_18_04
HOST2_FACILITY=sjc1
I am using hashmap as a set. The following doesn't quite work, because the "" empty string is not treated as an argument to @replace
.
let hosts:hmap[] = [ ]
let name = $replace("HOST1_USERFILE", "_USERFILE" "")
let hosts[$name] = $name
I could do use a space instead of empty string:
let name = $replace("HOST1_USERFILE", "_USERFILE" " ") # a space, inst
... but the space is preserved in the value of $name
.
I could use trim #802 (closed) when it lands, but a dedicated substring removal method might be nice.