Skip to reading
PCA Script Programming

15. Strings and useful text operations

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page
Code example
function run()
    let answer = lower(trim("  Open The Door  "))
    let words = split(answer, " ", false)
    let tidy = join(words, " ")
    let changed = replace(tidy, "door", "archive")
    return [answer, changed, starts_with(answer, "open")]
end

trim() removes whitespace at the ends. lower() and upper() change case. contains(), starts_with() and ends_with() accept an optional case-sensitive flag; it defaults to true. replace() replaces matching text with case-sensitive matching.

split(text, delimiter, allow_empty) makes an array. Its default delimiter is a space, and empty pieces are kept unless you pass false. join(array, delimiter) goes the other way. len(text),

length(text) and string_length(text) report length.

Code example
function run()
    let line = format("{name} found {count} gears.", {"name": "Ada", "count": 3})
    let numbered = format("{0}: {1}", ["Score", 25])
    return [line, numbered]
end

format() replaces braces with dictionary keys, zero-based array positions, or {value} for a single value. It is not a printf-style format engine. GUI wildcards such as $$score belong to the GUI text substitution system; ordinary PCA string values do not automatically expand them.

Page 22 of 357Permalink
Go to page