Quirrel4.41.0

types.String.toupper

Method on every string
pure string.toupper([start: number, end: number], ...): any

Returns a copy of str with the ASCII letters in [start, end) uppercased.

The binding carries no declaration string, so the VM cannot report parameter names. The names above are from this page; the types and attributes still come from the VM. The VM also cannot tell an optional parameter from a variadic tail here, so read the brackets and any trailing ... from the prose below, not from the signature.

Parameters

startnumberindex of the first byte to convert; defaults to 0 optional
endnumberindex one past the last byte to convert; defaults to str.len() optional
...anynot a real parameter; see Notes repeats

Return value

A copy of str the same length as the original, with every byte in [start, end) that is a-z replaced by its uppercase letter. Bytes outside the range, and bytes inside it that are not a-z (including any byte of a multi-byte character), are copied unchanged. With no arguments the whole string is uppercased.

Errors

Throws wrong indexes when end < start after negative indices are resolved (see types.String.tolower). Throws slice out of range when end > str.len() or the resolved start < 0.

Notes

Takes 0, 1 or 2 arguments, not the variadic tail the VM's dump implies. See the Notes on types.String.tolower for why an out-of-range range throws here but clamps for types.String.slice, and for the ASCII-only scope of the conversion.

Example

examples/types/string/toupper.nut
println("\"abc\".toupper() =", "abc".toupper())
println("\"abcdef\".toupper(1, 3) =", "abcdef".toupper(1, 3))

// non-ASCII bytes are never touched.
let mb = "\xD0\x9F\xD0\xBE"
println("mb.toupper() == mb =", mb.toupper() == mb)
Output:
"abc".toupper() = ABC
"abcdef".toupper(1, 3) = aBCdef
mb.toupper() == mb = true

See also

tolowerReturns a copy of str with the ASCII letters in [start, end) lowercased.
sliceReturns the bytes of str from start up to, but not including, end.
stringclass index