Skip to content

Instantly share code, notes, and snippets.

@tjbenton
Created September 8, 2014 17:14
Show Gist options
  • Save tjbenton/62c15099a1e8949be385 to your computer and use it in GitHub Desktop.
Save tjbenton/62c15099a1e8949be385 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.4.3)
// Compass (v1.0.1)
// ----
// @author Tyler Benton
// @page helpers/functions
// @description Splits string at the specified point
//
// @arg {string}
// @arg {string}
// @arg {list} - This is a temp list to make this function recursive and shouldn't be used.
//
// @returns {list}
@function str-split($str, $key: " ", $temp: ()){
$index: str-index($str, $key);
@return if($index != null,
str-split(str-slice($str, $index + 1), $key, append($temp, str-slice($str, 0, $index - 1), "comma")),
append($temp, $str)
);
}
// test
.str-split{
$string: "Lorem ipsum dolor sit amet, consectetur adipisicing elit.";
original: $string;
split-at-space: str-split($string);
split-at-comma: str-split($string, ",");
}
.str-split {
original: "Lorem ipsum dolor sit amet, consectetur adipisicing elit.";
split-at-space: "Lorem", "ipsum", "dolor", "sit", "amet,", "consectetur", "adipisicing", "elit.";
split-at-comma: "Lorem ipsum dolor sit amet", " consectetur adipisicing elit.";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment