Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Rebol Programming/replace

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

USAGE: REPLACE target search replace /all /case /tail DESCRIPTION: Replaces the search value with the replace value within the target series. REPLACE is a function value. ARGUMENTS target -- Series that is being modified (Type: series) search -- Value to be replaced (Type: any) replace -- Value to replace with (will be called each time if a function) (Type: any) REFINEMENTS /all -- Replace all occurrences /case -- Case-sensitive replacement /tail -- Return target after the last replacement position SOURCE CODE replace: func [ {Replaces the search value with the replace value within the target series.} target [series!] "Series that is being modified" search "Value to be replaced" replace {Value to replace with (will be called each time if a function)} /all "Replace all occurrences" /case "Case-sensitive replacement" /tail "Return target after the last replacement position" /local save-target len value pos do-break ][ save-target: target len: system/words/case [ bitset? :search 1 any-string? target [ if any [not any-string? :search tag? :search] [search: form :search] length? :search ] any-block? :search [length? :search] true 1 ] do-break: unless all [:break] while pick [ [pos: find target :search] [pos: find/case target :search] ] not case [ (value: replace pos) target: change/part pos :value len do-break ] either tail [target] [save-target] ]