String
Strings are traditionally a sequence of characters, but you can think of them as "text". Cheddar's strings are like Ruby's strings.

Basic Syntax

Strings in Cheddar are delimited by double quotes or single quotes. Additionally, Cheddar supports literal newlines within Strings.
1
"Hello, World!" // Both of these are
2
'Hello, World!' // exactly the same
Copied!
Whichever quote you use is your choice and varies based on your personal preference. For the rest of this documentation, double quotes will be used.

Using special characters

Cheddar is, again, like the C language in respect to escaping. You can use a backslash before a character to insert it's literal form rather than it to have a special meaning.
1
"This is a double quote: \"."
2
'This is a single quote: \'.'
3
"This is a blackslash: \\"
Copied!

Using formatting

"String formatting" is a way to insert the result of an expression directly into a string. Using #{ ... } you can "format" a string.
1
"2+2=#{2+2}" # evaluates 2+2 and returns 4
2
"2+2=4" # Has the same value as the above
Copied!
Backslashes also work to escape formatting:
1
"2+2=\#{2+2}" # Does NOT evaluate 2+2 or the format
Copied!
This evaluates to: 2+2=#{2+2}
Last modified 1yr ago