我注意到 strip() 对“[”符号没有反应(真的很奇怪)
julia> strip("a+b[2]", '[')
"a+b[2]"
julia> strip("a+b[2]", ']')
"a+b[2"
有人知道这是怎么回事吗?
最佳答案
strip
是 lstrip
和 rstrip
的组合,即它从左侧(开始)和右侧(结束)剥离字符字符串。它适用于以下情况:您想要删除某些内容周围多余的空格(当您只是传入一个字符串时这是默认设置),或者以其他方式删除围绕您的实际文本的不必要字符。
这是 strip 在许多其他语言中的常见含义,例如。 Python , Ruby等
要删除字符串中任意位置的字符,请使用replace
:
replace(s::AbstractString, pat=>r, [pat2=>r2, ...]; [count::Integer])
.... To remove instances of
pat from string, set r to the empty String ("").
julia> replace("a+b[2]", '[' => "")
"a+b2]"
https://stackoverflow.com/questions/73883112/