Created
October 27, 2015 22:39
-
-
Save sandersk/0c0f3b411586bad5f8e8 to your computer and use it in GitHub Desktop.
Native SassScript function for splitting strings on a given delimiter
This file contains 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
@function str-split($str, $del: ", ") { | |
$delimiter-length: str-length($del); | |
$delimiter-start-index: str-index($str, $del); | |
@if $delimiter-start-index != null { | |
$list-item: str-slice($str, 1, $delimiter-start-index - 1); | |
$rest-of-string: str-slice($str, $delimiter-start-index + $delimiter-length); | |
@return $list-item, str-to-list($rest-of-string, $del); | |
} | |
@else { | |
@return $str; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment