Substring replacement

Why does the following not work?

replace("2021-06-29T23:14:20", "-" => "", ":" => "")

Because replace only takes one pat => r argument. Try putting them in a tuple.

In the official document, the following works:

replace([1, 2, 1, 3], 1=>0, 2=>4, count=2)

That’s the method for an array. You can’t do that in a string (and it turns out, making a vector of substitution pairs won’t help):

This will work in 1.7.

2 Likes

Good to know this. Thank you, @Sukera

Converting string to array and back to string:

str = "2021-06-29T23:14:20"
join(replace(split(str,""), "-" => "", ":" => ""))

"20210629T231420"