Skip to main content

Text / string utilities (text)

Start here

text adds helpers for working with str values and mutable text bufferstext::length, text::trim, toUpper, concatenation, substring search, and a text::Text class when you want a mutable buffer. String equality in Flow-Wing is still == / != on str.

A tiny program

bring text

var s: str = "  FlowWing  "
println(text::trim(s))
println(text::toUpper("abc"))
println(text::length("hi"))

Output:

FlowWing
ABC
2

Free functions (complete list)

FunctionReturnsDescription
text::getLength(s)intLength of the string
text::length(s)intAlias for getLength
text::toUpper(s)strConvert to uppercase
text::toLower(s)strConvert to lowercase
text::reverse(s)strReverse the string
text::trim(s)strRemove leading/trailing whitespace
text::replace(s, target, replacement)strReplace all occurrences of target with replacement
text::concat(first, second)strConcatenate two strings
text::charAt(s, index)charCharacter at position index
text::isEmpty(s)boolTrue if the string is empty
text::equalsIgnoreCase(a, b)boolCase-insensitive equality check
text::substring(source, start, end)strExtract substring from start (inclusive) to end (exclusive)
text::indexOf(source, target)intFirst index of target in source, or -1 if not found

Substring examples

bring text

var s: str = "Hello World"
println(text::substring(s, 0, 5))
println(text::substring(s, 6, 11))
println(text::indexOf(s, "World"))

Output:

Hello
World
6

When to use text::Text

Use text::Text for a builder-style or in-place buffer you mutate (for example call toUpper() on the object, then get() to read a str). Use plain str and free functions when you do not need a long-lived buffer.

Mutable buffer example:

bring text

var t: text::Text = new text::Text("hello")
t.toUpper()
println(t.get())

Output:

HELLO

More detail: free functions and naming

Free functions include text::length, text::concat, text::toUpper, text::toLower, text::trim, text::replace, text::reverse, text::indexOf, and more. The text::Text class carries additional methods for in-place work. There is no separate legacy text::compare for ordering—== / != cover equality; for sorting semantics, use what your program's types and libraries provide.

Source & tests (if you have the repository)

WhatWhere
Module source (reference)fw-modules/text_module/text-module.fg.
Integration-style fixturestests/fixtures/LatestTests/StrModuleTests/bring, path helpers, substring / indexOf / mutation samples.