gearss / rebol / REBOL 3 Functions: read



REBOL 3 Functions: read

2021-12-05  gearss

REBOL 3 Functions: read

read  source  /part  length  /seek  index  /string  /lines

Read from a file, URL, or other port.


source [port! file! url! block!]


/part - Partial read a given number of units (source relative)

length [number!]

/seek - Read from a specific position (source relative)

index [number!]

/string - Convert UTF and line terminators to standard text string

/lines - Convert to block of strings (implies /string)

See also:

write   open   close   load   save  


Using READ is the simplest way to get information from a file or URL. This is a higher level port operation that opens a port, reads some or all of the data, then closes the port and returns the data that was read. When used on a file, or URL, the contents of the file, or URL are returned as a string.

The /LINES refinement returns read content as a series of lines. One line is created for each line terminator found in the read data.

The /PART refinement reads the specified number of elements from the file, URL, or port. Reading a file or URL will read the specified number of characters. Used with /LINES, it reads a specified number of lines.

See the User's Guide for more detailed explanation of using READ and its refinements.

write %rebol-test-file.r "text file"

print read %rebol-test-file.r


write %rebol-test-file.r [

{A learned blockhead is a greater man

than an ignorant blockhead.

    -- Rooseveldt Franklin}


probe first read/lines %rebol-test-file.r


probe pick (read/lines %rebol-test-file.r) 3

probe read/part %rebol-test-file.r 9

probe read/with %rebol-test-file.r "blockhead"

write/append %matrix.avi to-binary "abcdefg"


    来自: gearss > 《rebol》



    请遵守用户 评论公约

    类似文章 更多
    喜欢该文的人也喜欢 更多