LoginSignup
5
6

More than 5 years have passed since last update.

Julia で文字列操作 split とreplace

Last updated at Posted at 2018-11-29

Julia: ver.1.0.2を使用.

julia> hoge = ["ab", "ac"]
2-element Array{String,1}:
 "ab"
 "ac"

ドット.を付けることで要素ごとにsplitしてくれる.

julia> split.(hoge, "")
2-element Array{Array{SubString{String},1},1}:
 ["a", "b"]
 ["a", "c"]

ただし,replaceに関しては,要素ごとにreplaceしてくれない.
(Pair: "a"=>"c"もiterableだかららしい.)

julia> replace.(hoge, "a"=>"c")
ERROR: MethodError: no method matching replace(::String, ::String)

なので,"a"=>"c"もリスト化やタプル化する.

julia> replace.(hoge, ["a"=>"c"])
2-element Array{String,1}:
 "cb"
 "cc"
5
6
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6