Tutorialsteacher

Follow Us

Articles
  • C#
  • C# OOP
  • ASP.NET Core
  • ASP.NET MVC
  • LINQ
  • Inversion of Control (IoC)
  • Web API
  • JavaScript
  • TypeScript
  • jQuery
  • Angular 11
  • Node.js
  • D3.js
  • Sass
  • Python
  • Go lang
  • HTTPS (SSL)
  • Regex
  • SQL
  • SQL Server
  • PostgreSQL
  • MongoDB
  • Sass - Get Started
  • What is Sass
  • Sass - Setup Environment
  • Sass - Syntax
  • Sass - Variable
  • Sass - Script
  • Sass - Data Types
  • Sass - Operators
  • Sass - Functions
  • String Functions
  • Numeric Functions
  • List Functions
  • Map Functions
  • Selector Functions
  • Introspection Functions
  • Color Functions
  • Control Directives
  • Import Files and Partials
  • Sass - Mixins
  • Sass - Inheritance
Entity Framework Extensions - Boost EF Core 9
  Bulk Insert
  Bulk Delete
  Bulk Update
  Bulk Merge

Sass - String Functions

If you've worked in strings in a programming language, you'll be quite comfortable with the Sass string functions, with one exception: Sass strings are NOT zero-based arrays. The first character in a Sass string is at index 1, not 0.

For example. the Sass function str-index($string, $substring) returns the position of the first occurrence of $substring in $string. The equivalent JavaScript function is the indexOf(<substring>) method. But given the same arguments, they don't return the same values:

$str-index("hello","h"); //Sass returns 1

"hello".indexOf("h"); //JavaScript returns 0

The following table lists all string functions in Sass.

FunctionDescriptionExamples
unquote($string)Removes the quotes, if any, around a stringunquote("hello")
Result: hello
quote($string)Adds quotes to an unquoted string; returns a quoted string unmodifiedquote(hello)
Result: "hello"
quote("hello")
Result: "hello"
str-length($string)Returns the number of characters in a stringstr-length("hello")
Result: 5
str-insert($string, $insert, $index)Inserts the string specified as $insert at the specified index position inside stringstr-insert(" world", "hello", 0)
Result: "hello world"
str-index($string, $substring)Returns the index of the first occurrence of $substring inside $string, or null if the string is not foundstr-index("Hello", "H")
Result: 1
str-index("hello", "H")
Result: null
str-slice($string, $start-at, [$end-at])Returns a substring beginning at position $start-at and optionally ending at position $end-atstr-slice("hello, world", 8)
"world"
str-slice("hello, world", 8, 9)
Result: "wo"
to-upper-case($string)Returns a string containing $string converted to upper caseto-upper-case("hello")
Result:"HELLO"
to-lower-case($string)Returns a string containing $string converted to lower caseto-lower-case("Hello")
"hello"
TUTORIALSTEACHER.COM

TutorialsTeacher.com is your authoritative source for comprehensive technologies tutorials, tailored to guide you through mastering various web and other technologies through a step-by-step approach.

Our content helps you to learn technologies easily and quickly for learners of all levels. By accessing this platform, you acknowledge that you have reviewed and consented to abide by our Terms of Use and Privacy Policy, designed to safeguard your experience and privacy rights.

[email protected]

ABOUT USTERMS OF USEPRIVACY POLICY
copywrite-symbol

2024 TutorialsTeacher.com. (v 1.2) All Rights Reserved.