Soplang Logo
Soplang

Strings (qoraal)

Soplang strings: Unicode indexing, slicing, search, trimming, replacement, joining, and case conversion.

A string (qoraal) is a sequence of Unicode characters. Use double quotes ("...") or single quotes ('...'). Plain strings preserve backslashes. Prefix a string with e to decode escapes or with f to interpolate expressions. Triple quotes allow multiline text. String methods return new values without changing the original string.

Escapes and interpolation

string_forms.sop
door magac = "Ayaan"
qor(f"Salaan, {magac}!")
qor(e"safka koowaad\nsafka labaad")
door qoraalka = """safka koowaad
safka labaad"""
qor(qoraalka)

An r prefix explicitly requests raw text. Plain strings also preserve backslashes for compatibility. e strings decode escapes, including Unicode escapes. f strings evaluate expressions inside {...} and accept format specifiers. See the language reference for the literal syntax and text methods for string operations.

Creation, Length, and Indexing

strings_unicode.sop
qoraal magac = "Ayaan"
qor("Salaan, " + magac)    // Salaan, Ayaan
door qoraalka = "AĆ©šŸ™‚"
qor(qoraalka.dherer())     // 3
qor(qoraalka[1])           // Ć©
qor(qoraalka[-1])          // šŸ™‚
qor(qoraalka.hore())       // A
qor(qoraalka.dambe())      // šŸ™‚
qor(qoraalka.hel(9, "?"))  // ?

Positions count Unicode scalar values, rather than UTF-8 bytes or grapheme clusters. Negative indexes count from the end. An out-of-range read returns maran, as do hore() and dambe() on an empty string. Both dherer(text) and text.dherer() return the length.

MethodDescription
hel(index, default?)Read one character or return the supplied default
jar(start?, end?)Return a slice, excluding the end bound
leeyahay(sub)Check whether the string contains a substring
bilow(sub)Check whether the string starts with a substring
dhammaad(sub)Check whether the string ends with a substring
raadi(sub, direction?)Return the first or last matching index, or -1 when absent
tiri(sub)Count non-overlapping matches
strings_search.sop
door qoraalka = "moos iyo moos"
qor(qoraalka.jar(0, 4))        // moos
qor(qoraalka.jar(-4))          // moos
qor(qoraalka.raadi("moos"))    // 0
qor(qoraalka.raadi("moos", "dambe")) // 9
qor(qoraalka.raadi("canbe"))   // -1
qor(qoraalka.tiri("moos"))     // 2

jar() requires integer bounds. Bounds outside the string are clamped, and reversed bounds produce "". An optional direction for raadi() must be "hore" (first) or "dambe" (last). tiri("") produces an error. Search misses return maran for lists and -1 for strings.

Trimming and Transformation

MethodDescription
masax(direction?)Trim whitespace at both ends, or only "hore" / "dambe"
weynee()Convert to uppercase using Unicode case conversion
yaree()Convert to lowercase using Unicode case conversion
beddel(old, new, count?)Replace the first match, a specified number of matches, or all matches
kuceli(count)Repeat the string a specified number of times
strings_transform.sop
door qoraalka = "  Salaan  "
qor(qoraalka.masax())          // Salaan
qor(qoraalka.masax().weynee()) // SALAAN
qor("MOOS".yaree())            // moos
qor("aa-aa".beddel("a", "x"))  // xa-aa
qor("aa-aa".beddel("a", "x", 2)) // xx-aa
qor("aa-aa".beddel("a", "x", maran)) // xx-xx
qor("ha".kuceli(3))            // hahaha

With two arguments, beddel() replaces the first match. Its third argument may be a nonnegative integer limit, or maran to replace all matches. A limit of 0 leaves the string unchanged. kuceli() requires a nonnegative integer.

Splitting and Joining

qeybi(separator) returns a list of strings. xiriiri(values) joins the string representations of list items, using the receiver as the separator.

strings_split_join.sop
door magacyo = "Ayaan,Bilan,Hodan".qeybi(",")
qor(magacyo)                  // [Ayaan, Bilan, Hodan]
qor(" iyo ".xiriiri(magacyo))  // Ayaan iyo Bilan iyo Hodan
qor(", ".xiriiri([1, run, maran])) // 1, run, maran

These method names are shared with other language APIs where applicable. Supported earlier names are listed in the reference.

On this page