The sass:string module provides functions to work with strings in Sass, like changing case, slicing, and finding substrings.
Click to reveal answer
beginner
How do you convert a string to uppercase using sass:string?
Use the to-upper-case($string) function to change all letters in a string to uppercase.
Click to reveal answer
intermediate
What does the index($string, $substring) function do in sass:string?
It returns the position (1-based) of the first occurrence of $substring inside $string. Returns null if not found.
Click to reveal answer
intermediate
How can you get a part of a string in Sass using the sass:string module?
Use the slice($string, $start-at, $end-at) function to extract a substring from $start-at (inclusive) up to and including $end-at (both 1-based indexes).
Click to reveal answer
beginner
What is the difference between to-upper-case() and to-lower-case() in sass:string?
to-upper-case() changes all letters to uppercase, while to-lower-case() changes all letters to lowercase.
Click to reveal answer
Which function from sass:string returns the position of a substring inside a string?
Aindex()
Bslice()
Cto-upper-case()
Dlength()
✗ Incorrect
The index() function returns the 1-based position of a substring inside a string.
What will to-upper-case('hello') return?
A'hello'
B'HELLO'
C'Hello'
D'hElLo'
✗ Incorrect
to-upper-case() converts all letters to uppercase, so it returns 'HELLO'.
How do you extract characters 2 to 4 from the string 'Sass' using sass:string?
Aslice('Sass', 2, 4)
Bindex('Sass', 2, 4)
Cto-lower-case('Sass', 2, 4)
Dsubstring('Sass', 2, 4)
✗ Incorrect
slice() extracts a substring from start to end positions, so slice('Sass', 2, 4) returns 'ass'.
If a substring is not found, what does index() return?
A0
B1
C-1
Dnull
✗ Incorrect
index() returns null when the substring is not found.
Which function changes all letters in a string to lowercase?
Aslice()
Bto-upper-case()
Cto-lower-case()
Dindex()
✗ Incorrect
to-lower-case() converts all letters in a string to lowercase.
Explain how to find the position of a substring inside a string using the sass:string module.
Think about how you look for a word inside a sentence and want to know where it starts.
You got /3 concepts.
Describe how to change the case of letters in a string with sass:string functions.
Imagine you want all your text to be uppercase or lowercase for style.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of the sass:string module in Sass?
easy
A. To handle layout grids and flexbox
B. To create animations using keyframes
C. To manipulate and work with text strings in Sass stylesheets
D. To manage colors and gradients
Solution
Step 1: Understand the module's role
The sass:string module provides functions to work with text strings, such as changing case or joining strings.
Step 2: Compare with other options
Options A, B, and C relate to layout, animations, and colors, which are not the focus of the string module.
Final Answer:
To manipulate and work with text strings in Sass stylesheets -> Option C
Quick Check:
sass:string = text manipulation [OK]
Hint: Remember sass:string is for text, not colors or layout [OK]
Common Mistakes:
Confusing string module with color or layout modules
Thinking it handles animations
Assuming it manages Sass variables
2. Which of the following is the correct way to import the string module in Sass?
easy
A. @use 'sass:string';
B. @import 'string';
C. @require 'sass:string';
D. @include 'string';
Solution
Step 1: Recall Sass module import syntax
Modern Sass uses @use to import modules, so @use 'sass:string'; is correct.
Step 2: Identify incorrect options
@import is deprecated for modules, @require and @include are invalid for importing modules.
Final Answer:
@use 'sass:string'; -> Option A
Quick Check:
Use @use for modules [OK]
Hint: Use @use 'sass:string'; to import string module [OK]
C. Module name should be 'string-module' not 'sass:string'
D. Function name should be string.concat, not string.append
Solution
Step 1: Check function usage
string.append() expects string arguments, but 123 is a number, causing a type error.
Step 2: Verify other syntax
Semicolons are correct, module name and function name are valid as per Sass string module.
Final Answer:
Cannot append a number directly to a string -> Option B
Quick Check:
string.append needs strings, not numbers [OK]
Hint: Append only strings, convert numbers first [OK]
Common Mistakes:
Passing numbers without converting to strings
Confusing function names
Incorrect module import syntax
5. You want to create a Sass function that takes a string and returns it with the first letter capitalized and the rest lowercase. Which of these code snippets correctly uses the sass:string module to achieve this?
hard
A. @use 'sass:string';
@function capitalize($text) {
@return string.to-lower-case($text);
}