Skip to content

Instantly share code, notes, and snippets.

@chriseppstein
Created September 4, 2014 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriseppstein/50aad5193b566c050910 to your computer and use it in GitHub Desktop.
Save chriseppstein/50aad5193b566c050910 to your computer and use it in GitHub Desktop.
String Replacement function in pure-sass
@function str-replace($source, $substring, $replacement, $fail-silently: false) {
$start: str-index($source, $substring);
@if $start {
@return str-slice($source, 1, $start - 1) + $replacement + str-slice($source, $start + str-length($substring))
}
@if $fail-silently {
@return $source;
} @else {
@error "'#{$substring}' was not found in '#{$source}'";
}
}
@debug str-replace("beforeDURINGafter", "DURING", "REPLACED");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment