當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Julia readlines用法及代碼示例


用法:

readlines(io::IO=stdin; keep::Bool=false)
readlines(filename::AbstractString; keep::Bool=false)

將 I/O 流或文件的所有行作為字符串向量讀取。行為等同於保存使用相同參數重複讀取 readline 的結果並將結果行保存為字符串向量。

例子

julia> open("my_file.txt", "w") do io
           write(io, "JuliaLang is a GitHub organization.\nIt has many members.\n");
       end
57

julia> readlines("my_file.txt")
2-element Vector{String}:
 "JuliaLang is a GitHub organization."
 "It has many members."

julia> readlines("my_file.txt", keep=true)
2-element Vector{String}:
 "JuliaLang is a GitHub organization.\n"
 "It has many members.\n"

julia> rm("my_file.txt")

相關用法


注:本文由純淨天空篩選整理自julialang.org 大神的英文原創作品 Base.readlines — Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。