Jon*_*nas 4 string strip julia
strip当我尝试在 Julia 中输入字符串时,为什么会出现错误?
strip("Clean Monkeys", "s")
# expected
> "Clean Monkey"
# but got
> MethodError: objects of type String are not callable
Run Code Online (Sandbox Code Playgroud)
Jon*_*nas 10
在 Julia 中,字符周围的单撇号和双撇号之间存在差异(与 Python 和 R 等语言不同)。因此"s"被视为字符串和's'字符。
Strip 仅删除字符而不删除字符串。来自文档:
strip(str::AbstractString, chars) -> SubString
# This works
strip("Clean Monkeys", 's')
> "Clean Monkey"
# you can also provide lists of characters
strip("Clean Monkeys", ['e', 'y', 's'])
> "Clean Monk"
Run Code Online (Sandbox Code Playgroud)