DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Parse-replace - Parse-based Replace; Faster; Doesn't Change Series In Place

05.16.2006
| 2210 views |
  • submit to reddit
        
    parse-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."
        /all "Replace all occurrences."
        /case "Case-sensitive replacement."
        /local len data rule text
    ][
        len: length? search
        collect/into data [
            rule: [
                [copy text to search (if text [data: join text replace]) len skip]
                copy text to end (if text [data: text])
            ]
            if all [insert rule 'any]
            either case [parse/all/case target rule] [parse/all target rule]
        ] copy make target length? target
    ]