Skip to content

strrep

Replace all occurrences of a substring.

s = strrep(str1, str2, str3)

Returns str1 with every occurrence of the substring str2 replaced by str3. Replacements are made left-to-right; once a match is replaced, scanning continues after the replacement (no re-matching of inserted text).

strrep('hello world', 'world', 'there') % 'hello there'
strrep('a-b-c-d', '-', '_') % 'a_b_c_d'
  • regexprep
  • erase — Remove all occurrences of a pattern from a string.
  • strfind — Find one string within another.