Never been to DZone Snippets before?

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

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

parse-replace - parse-based replace; faster; doesn't change series in place

    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
    ]

parse-replace - parse-based REPLACE function

    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 skip-len rule text
    ][
        len: length? form search
        skip-len: length? form replace
        rule: copy [
            [to search mark: (change/part mark replace len) skip-len skip]
            to end
        ]
        if all [insert rule 'any]
        either case [parse/all/case target rule] [parse/all target rule]
        target
    ]
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS