Skip to content

substitute

Replace text by content (substring matching).

v = substitute(text, old_text, new_text, instance_num)

Returns text with old_text replaced by new_text. Without instance_num, replaces every occurrence; with it, replaces only the instance_num-th occurrence (1-based).

substitute('1-2-3-4', '-', '/') % '1/2/3/4'
substitute('1-2-3-4', '-', '/', 2) % '1-2/3-4'
  • replace — Replace a portion of a string at a specific position.
  • strrep — Replace all occurrences of a substring.