分享

REBOL 3 Functions: read

 gearss 2021-12-05

REBOL 3 Functions: read

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

Read from a file, URL, or other port.

Arguments:

source [port! file! url! block!]

Refinements:

/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  

Description

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

read

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

write

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"

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约