Sunday, 21 February 2016

Julia: replace: Replace given pattern

replace(string, pat, r[, n])
Search for the given pattern pat, and replace each occurrence with r.


Argument
Description
string
String to replace
pattern
Pattern to search for
r
Replace pattern with string r
n
It is optional, If n is provided, replace at most n occurrences.

julia> replace("1 told 2 is fine asked about 3", r"[0-9]", "personx")
"personx told personx is fine asked about personx"

julia> replace("1 told 2 is fine asked about 3", r"[0-9]", "personx", 1)
"personx told 2 is fine asked about 3"

julia> replace("1 told 2 is fine asked about 3", r"[0-9]", "personx", 2)
"personx told personx is fine asked about 3"






Previous                                                 Next                                                 Home

No comments:

Post a Comment