Skip to content

Instantly share code, notes, and snippets.

@tgdev
Created April 11, 2016 01:35
Show Gist options
  • Save tgdev/1328912e981da83000eff2d8b47b9267 to your computer and use it in GitHub Desktop.
Save tgdev/1328912e981da83000eff2d8b47b9267 to your computer and use it in GitHub Desktop.
A small sass helper function
/// Replace `$search` with `$replace` in `$string`
/// @author Hugo Giraudel
/// @param {String} $string - Initial string
/// @param {String} $search - Substring to replace
/// @param {String} $replace ('') - New value
/// @return {String} - Updated string
@function str-replace($string, $search, $replace: '') {
$index: str-index($string, $search);
@if $index {
@return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
}
@return $string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment