If a string needs to be changed in a predictable way but it's not feasible to do this at the source, or it's quite long and complicated, Replace provides a nice alternative. It lets you specify a value to find within a string, and replace it with a new substring of your choice.
Excel
In Excel, REPLACE uses a start index and length to determine the text being replaced, rather than searching for a specific string:
=~REPLACE!~(‹string›, ‹start_index›, ‹length›, ‹new_string›)
=REPLACE(F10,2,4,"Dev") // "BDMT001" -> "BDev01"
NB. If you don't know the ‹start_index›, you can use ~FIND!~(‹target_string›, ‹within_string›) to replace everything after a specified character, e.g.:
NB. This approach is case sensitive.
Option 2: Case sensitivity and Regex matching
~REGEX_REPLACE!~(‹within_string›, ‹target_string›, ‹new_string›«, case_sensitive»)
REGEX_REPLACE([Cost Code], "bdmt0", "BDev") // case insensitive
REGEX_REPLACE([Cost Code], "BDMT0", "BDev", 0) // case sensitive
NB. Omitting case_sensitive or setting it to 1 means that REGEX_REPLACE() will ignore case. Including a 0 will make it respect case.
Option 3: Replacement with a single character
~REPLACECHAR!~(‹within_string›, ‹target_characters›, ‹new_character›)
When «max_replacements» is omitted, all ‹target_strings› are replaced. Otherwise, only as many are replaced as specified by «max_replacements» (starting from the left).
The examples above assume variables have been declared for costCode and prodCode. For more information, go to General > Variables.