Tea — a strongly typed scripting language
Tea
DocsPlaygroundExamplesReferenceCommunity
GitHub

Tea Language

A strongly typed scripting language for native tools.

© 2026 Tea Language.

Agent documentationContributingCommunityRepository

Language Runtime

Built-ins

Standard Library

std.argsstd.assertstd.audiostd.encodingstd.envstd.fsstd.hashstd.httpstd.netstd.jsonstd.mathstd.parsestd.pathstd.processstd.randomstd.raylibstd.regexstd.stringstd.timestd.url

Read as Markdown

Standard Library

std.string

String manipulation utilities for common text operations.

Exported functions

pub def index_of(text: String, pattern: String) -> Int

Find the first occurrence of a substring.

pub def contains(text: String, pattern: String) -> Bool

Return true when the string contains a substring.

pub def split(text: String, delimiter: String) -> List[String]

Split a string by a delimiter.

Examples

use string from "std.string"

string.split("red,green,blue", ",") # => ["red", "green", "blue"]
pub def last_index_of(text: String, pattern: String) -> Int

Find the last occurrence of a substring.

pub def starts_with(text: String, prefix: String) -> Bool

Check if a string starts with a given prefix.

Examples

use string from "std.string"

string.starts_with("hello world", "hello") # => true
string.starts_with("hello world", "world") # => false
pub def ends_with(text: String, suffix: String) -> Bool

Check if a string ends with a given suffix.

Examples

string.ends_with("hello world", "world")  # => true
string.ends_with("hello world", "hello")  # => false
pub def trim_start(text: String) -> String

Trim whitespace from the start of a string.

Examples

string.trim_start("  hello  ")  # => "hello  "
string.trim_start("\t\nhello")  # => "hello"
pub def trim_end(text: String) -> String

Trim whitespace from the end of a string.

Examples

string.trim_end("  hello  ")  # => "  hello"
string.trim_end("hello\n\t")  # => "hello"
pub def trim(text: String) -> String

Trim whitespace from both ends of a string.

Examples

string.trim("  hello  ")  # => "hello"
string.trim("\t\nhello\n\t")  # => "hello"
pub def reverse(text: String) -> String

Reverse a string.

Examples

string.reverse("hello")  # => "olleh"
string.reverse("ab")  # => "ba"
pub def replace(text: String, pattern: String, replacement: String) -> String

Replace all occurrences of a substring with another string.

Examples

string.replace("hello world", "world", "tea")  # => "hello tea"
string.replace("foo bar foo", "foo", "baz")  # => "baz bar baz"
pub def replace_once(text: String, pattern: String, replacement: String) -> String

Replace the first occurrence of a substring with another string.

pub def to_lower(text: String) -> String

Convert a string to lowercase.

Examples

string.to_lower("Hello World")  # => "hello world"
string.to_lower("TEA")  # => "tea"
pub def to_upper(text: String) -> String

Convert a string to uppercase.

Examples

string.to_upper("Hello World")  # => "HELLO WORLD"
string.to_upper("tea")  # => "TEA"
pub def join(parts: List[String], separator: String) -> String

Join a list of strings with a separator.

pub def lines(text: String) -> List[String]

Split text into lines, trimming a trailing "\r" from each line and dropping the final empty line produced by a trailing newline.

pub def split_once(text: String, delimiter: String) -> List[String]?

Split a string into two parts at the first occurrence of a delimiter.

Examples

use string from "std.string"

const parts = string.split_once("name=green=tea", "=")
if parts != nil
  const pair = parts!
  @println(pair[0]) # name
  @println(pair[1]) # green=tea
end
@println(string.split_once("name", "=") == nil) # true
pub def rsplit_once(text: String, delimiter: String) -> List[String]?

Split a string into two parts at the last occurrence of a delimiter.

Examples

use string from "std.string"

const parts = string.rsplit_once("archive.tar.gz", ".")
if parts != nil
  @println(parts!) # [archive.tar, gz]
end
pub def count(text: String, pattern: String) -> Int

Count non-overlapping occurrences of a substring.

pub def strip_prefix(text: String, prefix: String) -> String?

Remove a prefix when present.

Examples

use string from "std.string"

@println(string.strip_prefix("Bearer token123", "Bearer ") ?? "") # token123
@println(string.strip_prefix("token123", "Bearer ") == nil) # true
pub def strip_suffix(text: String, suffix: String) -> String?

Remove a suffix when present.

Examples

use string from "std.string"

@println(string.strip_suffix("report.txt", ".txt") ?? "report.txt") # report
pub def repeat(text: String, times: Int) -> String

Repeat a string count times.

pub def pad_start_with(text: String, width: Int, fill: String) -> String

Pad a string on the left with a fill string until it reaches width.

Examples

use string from "std.string"

@println(string.pad_start_with("42", 5, "0")) # 00042
pub def pad_start(text: String, width: Int) -> String

Pad a string on the left with spaces until it reaches width.

pub def pad_end_with(text: String, width: Int, fill: String) -> String

Pad a string on the right with a fill string until it reaches width.

pub def pad_end(text: String, width: Int) -> String

Pad a string on the right with spaces until it reaches width.

Examples

use string from "std.string"

@println(string.pad_end("tea", 6) + "|") # tea   |