Created
November 13, 2013 16:32
-
-
Save Snugug/7452004 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ---- | |
| // Sass (v3.3.0.rc.1) | |
| // Compass (v0.13.alpha.10) | |
| // ---- | |
| $test: 'Hello World My Name Is Sam'; | |
| ////////////////////////////// | |
| // str-replace as single function | |
| ////////////////////////////// | |
| @function str-replace($string, $search, $replace) { | |
| $length: str-length($replace); | |
| $index: str-index($string, $search); | |
| $slice: $string; | |
| @while $index != 0 { | |
| $slice: str-slice($slice, 0, $index - 1); | |
| $slice: $slice + $replace; | |
| $slice: $slice + str-slice($string, $index + $length); | |
| @return str-replace($slice, $search, $replace); | |
| } | |
| @return $slice; | |
| } | |
| .single-function { | |
| content: str-replace($test, ' ', '-'); | |
| } | |
| ////////////////////////////// | |
| // str-replace as recursive function | |
| ////////////////////////////// | |
| @function str-replace($string, $search, $replace) { | |
| $index: str-index($string, $search); | |
| @if $index != 0 { | |
| $slice: str-slice($string, 0, $index - 1); | |
| $slice: $slice + $replace; | |
| $slice: $slice + str-slice($string, $index + str-length($replace)); | |
| @return str-replace($slice, $search, $replace); | |
| } | |
| @return $string; | |
| } | |
| .recursive-function { | |
| content: str-replace($test, ' ', '-'); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .single-function { | |
| content: "Hello-World-My-Name-Is-Sam"; | |
| } | |
| .recursive-function { | |
| content: "Hello-World-My-Name-Is-Sam"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment