FoundationsStrings and Text
Blorp by Example

Strings and Text

Strings are immutable UTF-8 text values, and chars use single quotes.

Interpolation

Use ${expr} inside a string to insert a Stringable value.

interpolate.brp
name: String = "Ada"
message: String = "Hello, " + name

Chars

A Char uses single quotes, such as 'A'.

char.brp
initial: Char = 'A'
print(initial.to_string())

Raw Strings

Raw strings such as r"..." keep backslashes literal and do not interpolate.

raw.brp
pattern: String = r"\d+\.\d+"

Triple Strings

Triple-quoted strings such as """...""" can span lines and preserve literal newlines.

triple.brp
message: String = """hello
world"""

Common String Methods

String methods include trim, split, lower, upper, capitalize, starts_with, and contains.

strings.brp
clean: String = " Alice ".trim().capitalize()

Example

display-label.brp
pure func display_label(raw: String) -> String:
	parts: List[String] = raw
		.trim()
		.split(" ")
	first: String = parts
		.get_or(0, "")
		.capitalize()
	last: String = parts
		.get_or(1, "")
		.capitalize()
	"${first} ${last}"


func main(args: List[String]) -> Void:
	initial: Char = 'A'
	pattern: String = r"\s+"
	banner: String = """Display label ready"""
	print(display_label(" Alice Smith "))
	print(initial.to_string() + " " + pattern + " " + banner)

Try It

terminal
blorp run display-label.brp