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

Change A File's Suffix

01.22.2006
| 1372 views |
  • submit to reddit
        
    change-suffix: func [
        {Changes the suffix of the string and returns the updated string.}
    	string [any-string!] "The file, url, string, etc. to change."
    	suffix [any-string!] "The new suffix."
    	;!! Need to have an updated SUFFIX? to make this easy.
    	;/with "Allows alternate delimiter."
    	;   delim [char!] {Specifies alternate for #"."}
    	/local s
    ][
        attempt [if #"." <> first suffix [suffix: join %. suffix]]
        append either s: find/last string suffix? string [clear s][string] suffix
    ]