-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent behaviour for replace
#28967
Comments
Yes, the multiple-pair method is missing. #25732 fixes this. |
This is a short alternative to julia> reduce(replace, ("1"=>"0", "2"=>"1"), init="1,2,3")
"0,1,3" |
Hiccup.jl use the macrotools package to do this htmlescape(s::AbstractString) =
@> s replace("&" => "&") replace("<" => "<") replace(">" => ">") but i found it's very overkill there. |
That's simply works Base.replace(s::String, oldnews::Pair...) = reduce(replace, oldnews, init=s)
using Test
@test Base.replace("a & b > c", "&"=>"&",">"=>">") == "a & b > c" |
See #30457. |
This has finally been implemented in #40484 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Julia Version 1.0.0
Steps to reproduce:
When acting on a String,
replace
argument is:replace(::AbstractString, pat=>r)
, where (quoting from the docs)On the contrary, when acting on a collection (although Strings are collections):
replace(collection, new_old::Pair...)
with variable number of arguments.replace
for Strings should follow the same semantics as for collection (maybe also implementing the version taking a function as argument). But the fact thatpat
can be an array of characters is useful for removing several characters for example.The text was updated successfully, but these errors were encountered: