Sass in the Real World: book 2 of 4

String functions

Function defintion Function description
unquote($string) Removes quotes from any string that is passed to the function
Example:
unquote("Arial"); //Arial
quote($string) Adds quotes to any string that is passed to the function
Example:
quote(sans-serif); //"sans-serif"
str-length($string) Retrieve the length of any string passed to the function
Example:
str-length("I am a string with a length of 33"); //33
str-insert($string, $insert, $index) This function will inster a string at the given index. If the $index has a positive value then the index will begin from the left side of the $string. If it has a negative value it will begin from the right side of the $string. If the $index value is out of bounds of the $string length then it will add it to the end (if it is a positive value) or it will add to the beginning (if it is a negative value).
Example:
str-insert("abcd", "efg", 5); //"abcdefg"
str-insert("abcd", "efg", 2); //"aefgbcd"
str-insert("abcd", "efg", -2); //"abcefgd"
str-insert("abcd", "efg", 10); //"abcdefg"
str-insert("abcd", "efg", -6); //"efgabcd"
str-index($string, $substring) Gives the index of the first occurence of the $substring value within the $string value
Example:
str-index("The quick brown fox jumps over the lazy dog", "fox"); //17
str-slice($string, $start-at, [$end-at]) Returns a new sliced string that matches the $start-at index and goes to the index of the $end-at value. The $end-at value is optional, if not provided then the string is sliced starting from the $start-at point and ending at the end of the string
Example:
str-slice("Humpty Dumpty sat on a wall, Humpty Dumpty had a great fall", 0, 27); //Humpty Dumpty sat on a wall str-slice("Humpty Dumpty sat on a wall, Humpty Dumpty had a great fall", 30); //Humpty Dumpty had a great fall
to-upper-case($string) This function will change the format of the string to all upper case
Example:
to-upper-case("you can't handle the truth!"); //"YOU CAN'T HANDLE THE TRUTH"
to-lower-case($string) This function will chnge the format of the string to all lower case
Example:
to-lower-case("SHHHH, WE'RE HUNTING WABBITS!"); //"shhhh, we're hunting wabbits!"