str.q

Python's string helpers with Python's spellings and semantics: strip lstrip rstrip, startswith endswith, removeprefix removesuffix, isalpha isdigit isalnum isspace isupper islower, printf and format. Every function takes one string or a list of strings; a symbol reads as its string. The is* predicates answer 0b for "" as Python does. lower, upper, vs, sv, ss and ssr are q's own and have no twin here.

Examples

.str.strip "  a b  "
.str.isdigit ("123";"12a";`45)
.str.format ("{} costs {:.2f}";"tea";1.5)

Entity Summary

EntitiesShort Description
.str.endswith[text;suffix]Does text end with suffix?
.str.format[msg]Python-style formatting (DuckDB's format grammar): {} {0} {:>8.2f} {:,}; a plain string only has {{ }} unescaped.
.str.isalnum[text]Is every character a letter or a digit, and is there at least one?
.str.isalpha[text]Is every character a letter, and is there at least one?
.str.isdigit[text]Is every character a digit, and is there at least one?
.str.islower[text]Is every cased character lower case, and is there at least one?
.str.isspace[text]Is every character whitespace, and is there at least one?
.str.isupper[text]Is every cased character upper case, and is there at least one?
.str.lstrip[text]Leading whitespace removed.
.str.printf[msg]C-style formatting (DuckDB's printf grammar): %d %s %.2f %'d groups thousands, %,d spells the comma; %r renders any q value; a plain string only has %% unescaped.
.str.removeprefix[text;prefix]text without one leading prefix, unchanged when it does not start with it.
.str.removesuffix[text;suffix]text without one trailing suffix, unchanged when it does not end with it.
.str.rstrip[text]Trailing whitespace removed.
.str.startswith[text;prefix]Does text begin with prefix?
.str.strip[text]Leading and trailing whitespace (" \t\n\r") removed; q's trim strips only spaces.

Entity Details

.str.format[msg]

Python-style formatting (DuckDB's format grammar): {} {0} {:>8.2f} {:,}; a plain string only has {{ }} unescaped.

Parameters:
  • msg - a format string, or a list of one plus its arguments

Examples

.str.format ("{:>6}|{:,}";"ab";1234567)

.str.isalnum[text]

Is every character a letter or a digit, and is there at least one? "_" is neither.

.str.islower[text]

Is every cased character lower case, and is there at least one? "abc1" is 1b.

.str.isupper[text]

Is every cased character upper case, and is there at least one? "ABC1" is 1b.

.str.printf[msg]

C-style formatting (DuckDB's printf grammar): %d %s %.2f %'d groups thousands, %,d spells the comma; %r renders any q value; a plain string only has %% unescaped.

Parameters:
  • msg - a format string, or a list of one plus its arguments

Examples

.str.printf ("%s: %'d rows in %.1fs";"trade";1234567;0.25)

.str.removeprefix[text;prefix]

text without one leading prefix, unchanged when it does not start with it.

Examples

.str.removeprefix["v1.2";"v"]

.str.startswith[text;prefix]

Does text begin with prefix? An empty prefix always does.

Examples

.str.startswith[("apple";"banana");"a"]