@@ -288,11 +288,27 @@ read!(filename::AbstractString, a) = open(io->read!(io, a), filename)
288
288
289
289
Read a string from an I/O stream or a file, up to and including the given delimiter byte.
290
290
The text is assumed to be encoded in UTF-8.
291
+
292
+ # Examples
293
+ ```jldoctest
294
+ julia> open("my_file.txt", "w") do io
295
+ write(io, "JuliaLang is a GitHub organization.\n It has many members.\n ");
296
+ end
297
+ 57
298
+
299
+ julia> readuntil("my_file.txt", 'L')
300
+ "JuliaL"
301
+
302
+ julia> readuntil("my_file.txt", '.')
303
+ "JuliaLang is a GitHub organization."
304
+
305
+ julia> rm("my_file.txt")
306
+ ```
291
307
"""
292
308
readuntil (filename:: AbstractString , args... ) = open (io-> readuntil (io, args... ), filename)
293
309
294
310
"""
295
- readline(stream ::IO=STDIN; chomp::Bool=true)
311
+ readline(io ::IO=STDIN; chomp::Bool=true)
296
312
readline(filename::AbstractString; chomp::Bool=true)
297
313
298
314
Read a single line of text from the given I/O stream or file (defaults to `STDIN`).
@@ -301,6 +317,22 @@ input end with `'\\n'` or `"\\r\\n"` or the end of an input stream. When `chomp`
301
317
true (as it is by default), these trailing newline characters are removed from the
302
318
line before it is returned. When `chomp` is false, they are returned as part of the
303
319
line.
320
+
321
+ # Examples
322
+ ```jldoctest
323
+ julia> open("my_file.txt", "w") do io
324
+ write(io, "JuliaLang is a GitHub organization.\n It has many members.\n ");
325
+ end
326
+ 57
327
+
328
+ julia> readline("my_file.txt")
329
+ "JuliaLang is a GitHub organization."
330
+
331
+ julia> readline("my_file.txt", chomp=false)
332
+ "JuliaLang is a GitHub organization.\n "
333
+
334
+ julia> rm("my_file.txt")
335
+ ```
304
336
"""
305
337
function readline (filename:: AbstractString ; chomp:: Bool = true )
306
338
open (filename) do f
@@ -321,12 +353,32 @@ function readline(s::IO=STDIN; chomp::Bool=true)
321
353
end
322
354
323
355
"""
324
- readlines(stream ::IO=STDIN; chomp::Bool=true)
356
+ readlines(io ::IO=STDIN; chomp::Bool=true)
325
357
readlines(filename::AbstractString; chomp::Bool=true)
326
358
327
359
Read all lines of an I/O stream or a file as a vector of strings. Behavior is
328
- equivalent to saving the result of reading `readline` repeatedly with the same
360
+ equivalent to saving the result of reading [ `readline`](@ref) repeatedly with the same
329
361
arguments and saving the resulting lines as a vector of strings.
362
+
363
+ # Examples
364
+ ```jldoctest
365
+ julia> open("my_file.txt", "w") do io
366
+ write(io, "JuliaLang is a GitHub organization.\n It has many members.\n ");
367
+ end
368
+ 57
369
+
370
+ julia> readlines("my_file.txt")
371
+ 2-element Array{String,1}:
372
+ "JuliaLang is a GitHub organization."
373
+ "It has many members."
374
+
375
+ julia> readlines("my_file.txt", chomp=false)
376
+ 2-element Array{String,1}:
377
+ "JuliaLang is a GitHub organization.\n "
378
+ "It has many members.\n "
379
+
380
+ julia> rm("my_file.txt")
381
+ ```
330
382
"""
331
383
function readlines (filename:: AbstractString ; chomp:: Bool = true )
332
384
open (filename) do f
0 commit comments