KScript documentazione
IT

Lingua

Tradotto automaticamente dall’inglese, che è la versione originale.

campi e metodi delle stringhe

Testo. Una stringa che contiene un numero può usare anche i metodi dei numeri.

Il testo è una string: qualsiasi cosa tra virgolette. 'Single quotes' mantengono esattamente ciò che scrivi, e "double quotes" inseriscono ciò che si trova in { }, quindi "Hello { $name }" legge la variabile. Per un testo su più righe, scrivi un blocco di testo tra le righe ```, che mantiene ogni a capo come scritto.

I metodi di testo non modificano mai il testo su cui vengono chiamati; ognuno restituisce un nuovo testo (oppure un numero, una lista o un bool), quindi concatenali o conserva il risultato in una variabile:

<let name="name" value="'  ada LOVELACE '" />
<let name="tidy" value="$name->trim()->title()" />
<echo value="$tidy" /> <!-- 'Ada Lovelace' because the spaces go and each word gets a capital -->
<echo value="$name" /> <!-- '  ada LOVELACE ' because the text itself is unchanged -->
$name = '  ada LOVELACE '
$tidy = $name->trim()->title()
echo $tidy   // 'Ada Lovelace' because the spaces go and each word gets a capital
echo $name   // '  ada LOVELACE ' because the text itself is unchanged

Le posizioni partono da 0, e una posizione negativa conta dalla fine. Un carattere come un'emoji occupa due posizioni, e nessun metodo lo divide a metà. I confronti distinguono le maiuscole dalle minuscole, a meno che tu non passi il flag ignore_case.

Scopri di più sul testo: count · count_of · is_empty · is_blank · is_numeric · contains · starts_with · ends_with · index_of · matches

Prendine una parte: first · last · slice · before · after · truncate · find_all

Pulisci e modifica: trim · squish · strip · replace · upper · lower · capitalize · title · case · pad · repeat · reverse · wrap · mask · normalize_unicode

Dividilo in una lista: split · lines · blocks · words · chars · numbers · grid · shapes

Leggilo come un altro valore: to_number · to_int · to_bool · to_date, oppure un altro formato con ->convert()

Rendilo sicuro da inviare: escape · url_encode · url_decode · to_base64 · from_base64 · md5 · sha1 · sha256 · sha512 · hmac

Un campo è un dato semplice sul valore, letto con un punto e senza parentesi: $value.name. Un metodo richiede argomenti o esegue un'operazione, e si chiama con ->: $value->name(arguments), oppure passando il valore con la pipe: $value |> name(arguments).

Da KScript.Core

#string->after(text: string, last?: bool) → string

Il testo dopo la prima volta che compare il testo (o l'ultima, con last), oppure l'intero testo se non compare: 'a.tar.gz'->after('.', last) è gz.

->after(text, last?) restituisce il testo dopo la prima volta che text compare, oppure dopo l'ultima volta con last. Quando text non c'è, ottieni indietro l'intero testo:

<let name="file" value="'archive.tar.gz'" />
<echo value="$file->after('.')" /> <!-- 'tar.gz' because it cuts at the first dot -->
<echo value="$file->after('.', last)" /> <!-- 'gz' because it cuts at the last dot -->
<echo value="'no-at-sign'->after('@')" /> <!-- 'no-at-sign' because there is no @ to cut at -->
$file = 'archive.tar.gz'
echo $file->after('.')          // 'tar.gz' because it cuts at the first dot
echo $file->after('.', last)    // 'gz' because it cuts at the last dot
echo 'no-at-sign'->after('@')   // 'no-at-sign' because there is no @ to cut at
ParametroAccetta
text obbligatoriostring
last facoltativoun flag: last oppure not last

Gli argomenti possono essere con nome: ->after(…, last: …).

Esempio
<echo>{ 'joan@example.com'->after('@') }</echo>
echo 'joan@example.com'->after('@')

#string->before(text: string, last?: bool) → string

Il testo prima della prima volta che compare il testo (o l'ultima, con last), oppure l'intero testo se non compare: 'a.tar.gz'->before('.', last) è a.tar.

->before(text, last?) restituisce il testo prima della prima volta che text compare, oppure prima dell'ultima volta con last. Quando text non c'è, ottieni indietro l'intero testo:

<let name="email" value="'joan@example.com'" />
<echo value="$email->before('@')" /> <!-- 'joan' -->
<echo value="'archive.tar.gz'->before('.', last)" /> <!-- 'archive.tar' because it cuts at the last dot -->
$email = 'joan@example.com'
echo $email->before('@')                 // 'joan'
echo 'archive.tar.gz'->before('.', last) // 'archive.tar' because it cuts at the last dot
ParametroAccetta
text obbligatoriostring
last facoltativoun flag: last oppure not last

Gli argomenti possono essere con nome: ->before(…, last: …).

Esempio
<echo>{ 'joan@example.com'->before('@') }</echo>
echo 'joan@example.com'->before('@')

#string->blocks() → string[]

Le parti del testo comprese tra righe vuote, ciascuna privata degli a capo che la circondano: 'a\nb\n\nc'->blocks() è ['a\nb', 'c'].

->blocks() divide il testo nelle righe vuote, quindi ogni blocco è un gruppo di righe. Un singolo a capo resta dentro un blocco; solo una riga vuota ne inizia uno nuovo. Ogni blocco viene privato degli a capo che lo circondano:

<let name="pantry">```text
    tea
    milk

    flour
    sugar
    eggs
    ```</let>

<let name="shelves" value="$pantry->blocks()" />
<echo value="$shelves->count()" /> <!-- 2 because one blank line splits the text in two -->
<echo value="$shelves->map(.lines()->count())" /> <!-- [2, 3] because the first block has 2 lines and the second 3 -->
$pantry = ```text
tea
milk

flour
sugar
eggs
```

$shelves = $pantry->blocks()
echo $shelves->count()                  // 2 because one blank line splits the text in two
echo $shelves->map(.lines()->count())   // [2, 3] because the first block has 2 lines and the second 3
Esempio
<echo>{ ('a' + @char_of(10) + @char_of(10) + 'b')->blocks() }</echo>
echo ('a' + @char_of(10) + @char_of(10) + 'b')->blocks()

#string->capitalize() → string

Il testo con la prima lettera in maiuscolo.

->capitalize() rende maiuscola la prima lettera e lascia invariato il resto:

<echo value="'élan and style'->capitalize()" /> <!-- 'Élan and style' because only the first letter changes -->
<echo value="'iPhone'->capitalize()" /> <!-- 'IPhone' -->
echo 'élan and style'->capitalize()   // 'Élan and style' because only the first letter changes
echo 'iPhone'->capitalize()           // 'IPhone'
Esempio
<echo>{ 'hello world'->capitalize() }</echo>
echo 'hello world'->capitalize()

#string->case(style: snake|kebab|camel|pascal) → string

Il testo come identificatore in uno stile: 'User ID'->case(snake) è user_id, kebab dà user-id, camel userId e pascal UserId.

->case(style) riscrive il testo come nome in uno stile: snake (user_id), kebab (user-id), camel (userId) o pascal (UserId). Trova le parole sia negli spazi, nei separatori sia nei cambi di maiuscola, così puoi passare da qualsiasi stile a qualsiasi altro:

<echo value="'Order Total'->case(snake)" /> <!-- 'order_total' -->
<echo value="'order_total'->case(camel)" /> <!-- 'orderTotal' -->
<echo value="'orderTotal'->case(kebab)" /> <!-- 'order-total' -->
<echo value="'order-total'->case(pascal)" /> <!-- 'OrderTotal' -->
echo 'Order Total'->case(snake)   // 'order_total'
echo 'order_total'->case(camel)   // 'orderTotal'
echo 'orderTotal'->case(kebab)    // 'order-total'
echo 'order-total'->case(pascal)  // 'OrderTotal'
ParametroAccetta
style obbligatoriouna di queste parole: snake|kebab|camel|pascal
Esempio
<echo>{ 'Order Total'->case(snake) }</echo>
echo 'Order Total'->case(snake)

#string->chars() → string[]

I caratteri, come lista.

->chars() restituisce i caratteri come lista, un testo per ciascuno. Un carattere come un'emoji è un solo elemento, comunque sia memorizzato:

<echo value="'tea'->chars()" /> <!-- ['t', 'e', 'a'] -->
<echo value="'👍🏽x'->chars()->count()" /> <!-- 2 because the thumb and its skin tone are one character -->
echo 'tea'->chars()   // ['t', 'e', 'a']
echo '👍🏽x'->chars()->count()   // 2 because the thumb and its skin tone are one character
Esempio
<echo>{ 'abc'->chars() }</echo>
echo 'abc'->chars()

#string->contains(text, ignore_case?: bool) → bool

Vero quando il testo contiene questo testo. Con ignore_case: true, maiuscole e minuscole corrispondono.

->contains(text, ignore_case?) è true quando il testo contiene text in qualsiasi punto. Con ignore_case, maiuscole e minuscole coincidono:

<echo value="'Green tea'->contains('tea')" /> <!-- true -->
<echo value="'Green tea'->contains('TEA')" /> <!-- false because case matters -->
<echo value="'Green tea'->contains('TEA', ignore_case)" /> <!-- true -->
echo 'Green tea'->contains('tea')                // true
echo 'Green tea'->contains('TEA')                // false because case matters
echo 'Green tea'->contains('TEA', ignore_case)   // true
ParametroAccetta
text obbligatorioqualsiasi valore
ignore_case facoltativoun flag: ignore_case oppure not ignore_case

Gli argomenti possono essere con nome: ->contains(…, ignore_case: …).

Esempio
<echo>{ 'hello world'->contains('world') }</echo>
echo 'hello world'->contains('world')

#string->count() → number

Il numero di caratteri.

->count() restituisce quanti caratteri ha il testo:

<echo value="'tea'->count()" /> <!-- 3 -->
<echo value="''->count()" /> <!-- 0 -->
echo 'tea'->count()   // 3
echo ''->count()      // 0
Esempio
<echo>{ 'hello'->count() }</echo>
echo 'hello'->count()

#string->count_of(match) → number

Quante volte compare un testo.

->count_of(match) conta quante volte compare un pezzo di testo. Le occorrenze non si sovrappongono:

<echo value="'banana'->count_of('an')" /> <!-- 2 because b-an-an-a has two -->
<echo value="'banana'->count_of('x')" /> <!-- 0 -->
echo 'banana'->count_of('an')   // 2 because b-an-an-a has two
echo 'banana'->count_of('x')    // 0
Esempio
<echo>{ 'banana'->count_of('a') }</echo>
echo 'banana'->count_of('a')

#string->ends_with(text, ignore_case?: bool) → bool

Vero quando il testo termina con questo testo. Con ignore_case: true, maiuscole e minuscole vengono considerate uguali.

->ends_with(text, ignore_case?) è true quando il testo termina con text:

<echo value="'photo.JPG'->ends_with('.jpg')" /> <!-- false because case matters -->
<echo value="'photo.JPG'->ends_with('.jpg', ignore_case)" /> <!-- true -->
echo 'photo.JPG'->ends_with('.jpg')                // false because case matters
echo 'photo.JPG'->ends_with('.jpg', ignore_case)   // true
ParametroAccetta
text obbligatorioqualsiasi valore
ignore_case facoltativoun flag: ignore_case oppure not ignore_case

Gli argomenti possono essere con nome: ->ends_with(…, ignore_case: …).

Esempio
<echo>{ 'notes.txt'->ends_with('.txt') }</echo>
echo 'notes.txt'->ends_with('.txt')

#string->escape() → string

Il testo con i caratteri HTML escapati.

->escape() rende il testo sicuro da inserire in HTML: <, >, & e le virgolette diventano entità, così ciò che un utente ha digitato viene mostrato come testo e non diventa markup:

<echo value="'&lt;b>Tea &amp; milk&lt;/b>'->escape()" /> <!-- '&lt;b&gt;Tea &amp; milk&lt;/b&gt;' -->
echo '<b>Tea & milk</b>'->escape()   // '&lt;b&gt;Tea &amp; milk&lt;/b&gt;'

Le pagine già eseguono l'escape di ciò che stampano; questo serve per l'HTML che costruisci tu.

Esempio
<echo>{ 'Say "hi" > 3'->escape() }</echo>
echo 'Say "hi" > 3'->escape()

#string->find_all(pattern: regex) → string[]

Ogni corrispondenza di un'espressione regolare, come elenco.

->find_all(pattern) restituisce ogni corrispondenza di un'espressione regolare, in ordine:

<echo value="'tea 12, milk 7'->find_all(/\d+/)" /> <!-- ['12', '7'] because those are the runs of digits -->
echo 'tea 12, milk 7'->find_all(/\d+/)   // ['12', '7'] because those are the runs of digits

->numbers() restituisce i numeri stessi, come numeri.

ParametroAccetta
pattern obbligatorioregex
Esempio
<echo>{ 'Call 555-1234 or 555-9876'->find_all('[0-9]{3}-[0-9]{4}') }</echo>
echo 'Call 555-1234 or 555-9876'->find_all('[0-9]{3}-[0-9]{4}')

#string->first() → string

Il primo carattere.

->first() restituisce il primo carattere, oppure '' per un testo vuoto:

<echo value="'tea'->first()" /> <!-- 't' -->
<echo value="''->first()" /> <!-- '' -->
echo 'tea'->first()   // 't'
echo ''->first()      // ''
Esempio
<echo>{ 'Joan'->first() }</echo>
echo 'Joan'->first()

#string->from_base64() → string

Testo in Base64 decodificato.

->from_base64() decodifica un testo in base64 riportandolo al testo da cui è stato creato. Un testo che non è in base64 genera un errore:

<echo value="'dGVh'->from_base64()" /> <!-- 'tea' -->
echo 'dGVh'->from_base64()   // 'tea'
Esempio
<echo>{ 'aGVsbG8='->from_base64() }</echo>
echo 'aGVsbG8='->from_base64()

#string->grid() → string[][]

Il testo come righe di caratteri, una lista per riga, per mappe e labirinti: '#.\n.#'->grid() è [['#', '.'], ['.', '#']]. Un a capo alla fine non aggiunge una riga vuota. Leggi una cella con $grid[row][column], e scorri le sue righe o colonne con ->cells(rows) o ->cells(columns).

->grid() trasforma righe di caratteri in righe di singoli caratteri, quindi $grid[row][column] è un solo carattere. La riga 0 è la prima riga in alto e la colonna 0 il primo carattere. Un a capo alla fine non aggiunge una riga vuota:

<let name="garden">```text
    #.#
    ..#
    ```</let>

<let name="plot" value="$garden->grid()" />
<echo value="$plot" /> <!-- [['#', '.', '#'], ['.', '.', '#']] -->
<echo value="$plot[0][1]" /> <!-- '.' because row 0 is #.# and column 1 is its middle -->
<echo value="$plot[1][2]" /> <!-- '#' because row 1 is ..# and column 2 is its last -->
$garden = ```text
#.#
..#
```

$plot = $garden->grid()
echo $plot          // [['#', '.', '#'], ['.', '.', '#']]
echo $plot[0][1]    // '.' because row 0 is #.# and column 1 is its middle
echo $plot[1][2]    // '#' because row 1 is ..# and column 2 is its last

Per scorrere le righe o le colonne, leggi la griglia con ->cells(rows) o ->cells(columns).

Esempio
<echo>{ ('#.' + @char_of(10) + '.#')->grid() }</echo>
echo ('#.' + @char_of(10) + '.#')->grid()

#string->hmac(key, algorithm?: sha256|sha1|sha512) → string

L'HMAC del testo con una chiave segreta, in esadecimale (SHA-256 per impostazione predefinita), come si creano le firme dei webhook. Confronta le firme con @secure_equals().

->hmac(key, algorithm?) firma il testo con una chiave segreta e restituisce la firma in esadecimale, SHA-256 a meno che non passi sha1 o sha512. È il modo in cui i webhook dimostrano da dove proviene un messaggio. Confronta le firme con @secure_equals(), che richiede lo stesso tempo indipendentemente da quanto le due coincidano:

<let name="body" value="'{&quot;id&quot;: 1}'" />
<let name="signature" value="$body->hmac('whsec_test')" />
<echo value="$signature->count()" /> <!-- 64 because SHA-256 in hex is 64 characters -->
<echo value="@secure_equals($signature, $body->hmac('whsec_test'))" /> <!-- true because the same key signs the same text the same way -->
$body = '{"id": 1}'
$signature = $body->hmac('whsec_test')
echo $signature->count()                                    // 64 because SHA-256 in hex is 64 characters
echo @secure_equals($signature, $body->hmac('whsec_test'))  // true because the same key signs the same text the same way
ParametroAccetta
key obbligatorioqualsiasi valore
algorithm facoltativouna di queste parole: sha256|sha1|sha512

Gli argomenti possono essere con nome: ->hmac(…, algorithm: …).

Esempio
<echo>{ '{"id": 1}'->hmac('whsec_test') }</echo>
echo '{"id": 1}'->hmac('whsec_test')

#string->index_of(text, ignore_case?: bool, last?: bool) → number

Dove il testo compare per la prima volta, oppure con last, dove compare per l'ultima volta; -1 se non compare. Con ignore_case, maiuscole e minuscole coincidono.

->index_of(text, ignore_case?, last?) restituisce la posizione in cui text compare per la prima volta, oppure con last, dove compare per l'ultima volta. Restituisce -1 quando text non c'è:

<echo value="'banana'->index_of('an')" /> <!-- 1 because positions start at 0 -->
<echo value="'banana'->index_of('an', last)" /> <!-- 3 -->
<echo value="'banana'->index_of('x')" /> <!-- -1 -->
echo 'banana'->index_of('an')         // 1 because positions start at 0
echo 'banana'->index_of('an', last)   // 3
echo 'banana'->index_of('x')          // -1
ParametroAccetta
text obbligatorioqualsiasi valore
ignore_case facoltativoun flag: ignore_case oppure not ignore_case
last facoltativoun flag: last oppure not last

Gli argomenti possono essere con nome: ->index_of(…, ignore_case: …, last: …).

Esempio
<echo>{ 'hello'->index_of('l') }</echo>
echo 'hello'->index_of('l')

#string->is_blank() → bool

Vero quando il testo è vuoto o contiene solo spazi bianchi.

->is_blank() è true quando il testo è vuoto o contiene solo spazi, tabulazioni e a capo. Usalo per controllare ciò che un utente ha digitato in un modulo:

<echo value="''->is_blank()" /> <!-- true -->
<echo value="'   '->is_blank()" /> <!-- true because spaces alone count as blank -->
<echo value="' tea '->is_blank()" /> <!-- false -->
echo ''->is_blank()       // true
echo '   '->is_blank()    // true because spaces alone count as blank
echo ' tea '->is_blank()  // false
Esempio
<echo>{ '   '->is_blank() }</echo>
echo '   '->is_blank()

#string->is_empty() → bool

Vero quando il testo ha zero caratteri.

->is_empty() è true quando il testo non ha alcun carattere. Gli spazi contano come caratteri, quindi ' ' non è vuoto; usa ->is_blank() per quello:

<echo value="''->is_empty()" /> <!-- true -->
<echo value="'   '->is_empty()" /> <!-- false because it has three spaces -->
echo ''->is_empty()      // true
echo '   '->is_empty()   // false because it has three spaces
Esempio
<echo>{ ''->is_empty() }</echo>
echo ''->is_empty()

#string->is_numeric() → bool

Vero quando l'intero testo è un numero, come '42', '-3.5' o '1e3'. Sono ammessi spazi attorno al numero.

->is_numeric() è vero quando l'intero testo è un numero, come '42', '-3.5' o '1e3'. Sono ammessi spazi attorno al numero:

<echo value="'42'->is_numeric()" /> <!-- true -->
<echo value="' -3.5 '->is_numeric()" /> <!-- true because the spaces around it are fine -->
<echo value="'42 cats'->is_numeric()" /> <!-- false because cats isn't part of a number -->
echo '42'->is_numeric()      // true
echo ' -3.5 '->is_numeric()  // true because the spaces around it are fine
echo '42 cats'->is_numeric() // false because cats isn't part of a number
Esempio
<echo>{ ['42', '-3.5', 'abc']->map(fn(t) => $t->is_numeric()) }</echo>
echo ['42', '-3.5', 'abc']->map(fn(t) => $t->is_numeric())

#string->last() → string

L'ultimo carattere.

->last() restituisce l'ultimo carattere, oppure '' per un testo vuoto:

<echo value="'tea'->last()" /> <!-- 'a' -->
echo 'tea'->last()   // 'a'
Esempio
<echo>{ 'Joan'->last() }</echo>
echo 'Joan'->last()

#string->lines() → string[]

Le righe del testo, come elenco.

->lines() restituisce un testo per ogni riga. Una riga vuota dà un testo vuoto, così puoi trovare le interruzioni tra i gruppi:

<let name="note">```text
    tea
    milk

    juice
    ```</let>

<echo value="$note->lines()" /> <!-- ['tea', 'milk', '', 'juice'] -->
<echo value="$note->lines()->count()" /> <!-- 4 because the blank line is a line too -->
$note = ```text
tea
milk

juice
```

echo $note->lines()          // ['tea', 'milk', '', 'juice']
echo $note->lines()->count() // 4 because the blank line is a line too

->blocks() divide invece il testo nelle righe vuote.

Esempio
<echo>{ ('one' + @char_of(10) + 'two')->lines() }</echo>
echo ('one' + @char_of(10) + 'two')->lines()

#string->lower() → string

Il testo in minuscolo.

->lower() restituisce il testo in minuscolo:

<echo value="'Green TEA'->lower()" /> <!-- 'green tea' -->
echo 'Green TEA'->lower()   // 'green tea'
Esempio
<echo>{ 'HELLO'->lower() }</echo>
echo 'HELLO'->lower()

#string->mask(char?: string, keep_end?: number) → string

Il testo con ogni carattere sostituito da char (* per impostazione predefinita), tranne gli ultimi keep_end caratteri: ->mask('*', keep_end: 4) mostra solo gli ultimi quattro.

->mask(char?, keep_end?) nasconde il testo dietro un carattere, * a meno che tu non ne indichi un altro, mantenendo gli ultimi keep_end caratteri perché il lettore possa riconoscerlo:

<echo value="'4242424242424242'->mask('*', keep_end: 4)" /> <!-- '************4242' because only the last 4 show -->
<echo value="'secret'->mask()" /> <!-- '******' -->
echo '4242424242424242'->mask('*', keep_end: 4)   // '************4242' because only the last 4 show
echo 'secret'->mask()                             // '******'
ParametroAccetta
char facoltativostring
keep_end facoltativonumber

Gli argomenti possono essere con nome: ->mask(…, keep_end: …).

Esempio
<echo>{ '4242424242424242'->mask('*', keep_end: 4) }</echo>
echo '4242424242424242'->mask('*', keep_end: 4)

#string->matches(pattern: regex) → bool

Vero quando il testo corrisponde a un'espressione regolare: ->matches(/^[a-z]+$/i).

->matches(pattern) è vero quando un'espressione regolare trova una corrispondenza nel testo. Ancorala con ^ e $ per verificare l'intero testo:

<echo value="'Tea'->matches(/^[a-z]+$/i)" /> <!-- true because i ignores case -->
<echo value="'Tea2'->matches(/^[a-z]+$/i)" /> <!-- false because 2 isn't a letter -->
echo 'Tea'->matches(/^[a-z]+$/i)   // true because i ignores case
echo 'Tea2'->matches(/^[a-z]+$/i)  // false because 2 isn't a letter
ParametroAccetta
pattern obbligatorioregex
Esempio
<echo>{ '2026-11-19'->matches('^[0-9]{4}-[0-9]{2}-[0-9]{2}$') }</echo>
echo '2026-11-19'->matches('^[0-9]{4}-[0-9]{2}-[0-9]{2}$')

#string->md5() → string

L'hash MD5 del testo, in esadecimale.

->md5() restituisce l'hash MD5 del testo in esadecimale. È veloce e va bene per una chiave di cache o un checksum, ma non per le password o le firme:

<echo value="'tea'->md5()" /> <!-- '7239ea2b5dc943f61f3c0a0276c20974' -->
<echo value="'tea'->md5()->count()" /> <!-- 32 because MD5 in hex is 32 characters -->
echo 'tea'->md5()           // '7239ea2b5dc943f61f3c0a0276c20974'
echo 'tea'->md5()->count()  // 32 because MD5 in hex is 32 characters
Esempio
<echo>{ 'hello'->md5() }</echo>
echo 'hello'->md5()

#string->normalize_unicode(form?: NFC|NFD|NFKC|NFKD) → string

Normalizza Unicode usando la forma indicata (NFC per impostazione predefinita).

->normalize_unicode(form?) fa sì che testi che appaiono uguali si confrontino come uguali. é può essere memorizzato come un solo carattere o come e più un accento; NFC (il predefinito) li unisce, NFD li separa:

<echo value="'café'->normalize_unicode(NFD)->count()" /> <!-- 5 because NFD stores é as e and an accent -->
<echo value="'café'->normalize_unicode()->count()" /> <!-- 4 -->
echo 'café'->normalize_unicode(NFD)->count()   // 5 because NFD stores é as e and an accent
echo 'café'->normalize_unicode()->count()      // 4
ParametroAccetta
form facoltativouna di queste parole: NFC|NFD|NFKC|NFKD
Esempio
<echo>{ ('e' + @char_of(769))->normalize_unicode() }</echo>
echo ('e' + @char_of(769))->normalize_unicode()

#string->numbers() → number[]

Ogni numero nel testo, in ordine, come numeri: 'x=-3, y=12'->numbers() è [-3, 12]. Un meno rende il numero negativo a meno che una lettera o una cifra non compaia subito prima; quindi '1-3'->numbers() è [1, 3].

->numbers() restituisce ogni numero scritto nel testo, in ordine, come numeri. Un meno conta come segno quando non è unito a nulla alla sua sinistra, come in x=-3; tra due numeri, come in 1-3, è un trattino:

<echo value="'move 3 boxes from -1 to 12'->numbers()" /> <!-- [3, -1, 12] because -1 has a space before its minus -->
<echo value="'pages 4-9'->numbers()" /> <!-- [4, 9] because the minus joins 4 and 9, so it is a dash -->
<echo value="'price 2.50, qty 4'->numbers()" /> <!-- [2.5, 4] -->
echo 'move 3 boxes from -1 to 12'->numbers()  // [3, -1, 12] because -1 has a space before its minus
echo 'pages 4-9'->numbers()                   // [4, 9] because the minus joins 4 and 9, so it is a dash
echo 'price 2.50, qty 4'->numbers()           // [2.5, 4]
Esempio
<echo>{ 'x=-3, y=12'->numbers() }</echo>
echo 'x=-3, y=12'->numbers()

#string->pad(width: number, char?, start?: bool) → string

Il testo riempito alla fine fino a width, oppure all'inizio con start: '7'->pad(3, '0', start) è 007.

->pad(width, char?, start?) aggiunge un carattere, uno spazio a meno che tu non ne indichi un altro, finché il testo non raggiunge width caratteri. Riempie alla fine, oppure all'inizio con start. Il testo già di quella lunghezza non viene modificato:

<echo value="'7'->pad(3, '0', start)" /> <!-- '007' because two zeros go in front -->
<echo value="'tea'->pad(5, '.')" /> <!-- 'tea..' -->
<echo value="'teapot'->pad(3)" /> <!-- 'teapot' because it is already longer than 3 -->
echo '7'->pad(3, '0', start)   // '007' because two zeros go in front
echo 'tea'->pad(5, '.')        // 'tea..'
echo 'teapot'->pad(3)          // 'teapot' because it is already longer than 3
ParametroAccetta
width obbligatorionumber
char facoltativoqualsiasi valore
start facoltativoun flag: start o not start

Gli argomenti possono essere con nome: ->pad(…, char: …, start: …).

Esempio
<echo>{ '7'->pad(3, '0', start) }</echo>
echo '7'->pad(3, '0', start)

#string->repeat(count: number) → string

Il testo ripetuto count volte.

->repeat(count) restituisce il testo ripetuto count volte:

<echo value="'ha'->repeat(3)" /> <!-- 'hahaha' -->
<echo value="'-'->repeat(10)" /> <!-- '- -- -- -- -- -' -->
echo 'ha'->repeat(3)    // 'hahaha'
echo '-'->repeat(10)    // '----------'
ParametroAccetta
count obbligatorionumber
Esempio
<echo>{ 'ab'->repeat(3) }</echo>
echo 'ab'->repeat(3)

#string->replace(old, new, ignore_case?: bool) → string

The text with every old replaced by new. old can be a regex: ->replace(/\s+/, ' '), and new can use its groups as $1 or $. With ignore_case, plain text matches in any case.

->replace(old, new, ignore_case?) sostituisce ogni old con new. old può essere un'espressione regolare, e in quel caso new può usare ciò che i suoi gruppi hanno trovato come $1 o ${name}:

<echo value="'banana'->replace('a', 'o')" /> <!-- 'bonono' because every a changes -->
<echo value="'Tea'->replace('t', 'p', ignore_case)" /> <!-- 'pea' because T matches t -->
<echo value="'too   many  spaces'->replace(/\s+/, ' ')" /> <!-- 'too many spaces' -->
<echo value="'2026-12-01'->replace(/(\d+)-(\d+)-(\d+)/, '$3/$2/$1')" /> <!-- '01/12/2026' because the groups swap places -->
echo 'banana'->replace('a', 'o')                   // 'bonono' because every a changes
echo 'Tea'->replace('t', 'p', ignore_case)         // 'pea' because T matches t
echo 'too   many  spaces'->replace(/\s+/, ' ')    // 'too many spaces'
echo '2026-12-01'->replace(/(\d+)-(\d+)-(\d+)/, '$3/$2/$1')   // '01/12/2026' because the groups swap places
ParametroAccetta
old obbligatorioqualsiasi valore
new obbligatorioqualsiasi valore
ignore_case facoltativoun flag: ignore_case oppure not ignore_case

Gli argomenti possono essere con nome: ->replace(…, new: …, ignore_case: …).

Esempio
<echo>{ 'Hello, World'->replace(old: 'World', new: 'Joan') }</echo>
echo 'Hello, World'->replace(old: 'World', new: 'Joan')

#string->reverse() → string

Il testo al contrario.

->reverse() restituisce i caratteri in ordine inverso, mantenendo ciascun carattere intero:

<echo value="'stressed'->reverse()" /> <!-- 'desserts' -->
echo 'stressed'->reverse()   // 'desserts'
Esempio
<echo>{ 'stressed'->reverse() }</echo>
echo 'stressed'->reverse()

#string->sha1() → string

L'hash SHA-1 del testo, in esadecimale. Usalo solo dove un altro sistema richiede SHA-1.

->sha1() restituisce l'hash SHA-1 del testo in esadecimale, 40 caratteri. Preferisci ->sha256() per qualsiasi nuovo codice:

<echo value="'tea'->sha1()->count()" /> <!-- 40 -->
echo 'tea'->sha1()->count()   // 40
Esempio
<echo>{ 'hello'->sha1() }</echo>
echo 'hello'->sha1()

#string->sha256() → string

L'hash SHA-256 del testo, in esadecimale.

->sha256() restituisce l'hash SHA-256 del testo in esadecimale, 64 caratteri. Lo stesso testo dà sempre lo stesso hash, e ogni modifica ne dà uno diverso:

<echo value="'tea'->sha256()->count()" /> <!-- 64 -->
<echo value="'tea'->sha256() == 'tea'->sha256()" /> <!-- true because the same text gives the same hash -->
<echo value="'tea'->sha256() == 'Tea'->sha256()" /> <!-- false because one letter changed -->
echo 'tea'->sha256()->count()                  // 64
echo 'tea'->sha256() == 'tea'->sha256()        // true because the same text gives the same hash
echo 'tea'->sha256() == 'Tea'->sha256()        // false because one letter changed
Esempio
<echo>{ 'hello'->sha256() }</echo>
echo 'hello'->sha256()

#string->sha512() → string

L'hash SHA-512 del testo, in esadecimale.

->sha512() restituisce l'hash SHA-512 del testo in esadecimale, 128 caratteri:

<echo value="'tea'->sha512()->count()" /> <!-- 128 -->
echo 'tea'->sha512()->count()   // 128
Esempio
<echo>{ 'hello'->sha512()->slice(0, 16) }</echo>
echo 'hello'->sha512()->slice(0, 16)

#string->shapes(mask?: any, square?: bool, rectangle?: bool, line?: bool, circle?: bool, of?: any, rotated?: bool, size?: number, radius?: number, distance?: straight|steps|moves) → list

Every place a mask fits (->shapes(Tree), or ->shapes([Block, Ell]) for several), and every square, rectangle, line or circle (name one or several: ->shapes(square, circle, of: '#')) made by the cells that hold of: (a value, or a regex). It looks through text (each line a row, each character a cell, a blank line between layers), a list of values (one row), a grid ($grid[row][column]) or a 3D list ($cube[layer][row][column]); the built-in shapes also take a list of points { row, column }. A mask is a type that extends Mask: its layout is a picture, one character a cell, and each character matches a cell holding the same character, unless its symbols say otherwise (a value, a regex, a fn(cell), or any for a cell that isn't part of the shape). Each match is { kind, points }: kind is the mask's name or the shape, and each point is { row, column, value } (with symbol for a mask, and layer in 3D). With rotated, a mask is tried turned every way the input allows (back to front in a row, the four quarter turns in a grid, all 24 ways round in 3D), and squares, rectangles and lines may lean. A line needs size:, and a circle radius: and distance: straight (the default), steps or moves.

->shapes(mask?, square?, rectangle?, line?, circle?, of?, rotated?, size?, radius?, distance?) finds shapes drawn in text. Each line is a row and each character a cell, so the text doesn't need ->grid() first, and a blank line starts the next layer of a 3D input. It works as the list method does: name a mask first (a type that extends Mask, or a list of them), or one of the built-in shapes with of: to say which cells make it. Each match comes back as { kind, points }, and each point says its row, column, value and the mask's symbol drawn over it. See list ->shapes() for every argument.

<let name="orchard">```text
    #.#.#
    .#...
    #.#.#
    ```</let>

<type name="Tree" extends="Mask">
  <field name="layout" default="```text
      #.#
      .#.
      ```" />
  <field name="symbols" default="{ '.': any }" />
</type>

<echo value="$orchard->shapes(Tree)->count()" /> <!-- 1 because the V of three trees fits only at the top left -->
<echo value="$orchard->shapes(Tree, rotated)->count()" /> <!-- 4 because turned upside down and on its sides it fits three more places -->
<echo value="$orchard->shapes(Tree)->first().points->map(.column)" /> <!-- [0, 2, 1] because the points come in reading order: the top two, then the middle -->
$orchard = ```text
#.#.#
.#...
#.#.#
```

type Tree extends Mask {
  layout: ```text
    #.#
    .#.
    ```
  symbols: { '.': any }
}

echo $orchard->shapes(Tree)->count()                      // 1 because the V of three trees fits only at the top left
echo $orchard->shapes(Tree, rotated)->count()             // 4 because turned upside down and on its sides it fits three more places
echo $orchard->shapes(Tree)->first().points->map(.column) // [0, 2, 1] because the points come in reading order: the top two, then the middle
ParametroAccetta
mask optionalany
square optionalun flag: square o not square
rectangle optionalun flag: rectangle o not rectangle
line optionalun flag: line o not line
circle optionalun flag: circle o not circle
of optionalany
rotated optionalun flag: rotated o not rotated
size facoltativonumber
radius optionalnumber
distance optionaluna di queste parole: straight|steps|moves

Gli argomenti possono essere nominati: ->shapes(…, square: …, rectangle: …).

Esempio
<echo>{ ('##' + @char_of(10) + '##')->shapes(square, of: '#')->count() }</echo>
echo ('##' + @char_of(10) + '##')->shapes(square, of: '#')->count()

#string->slice(start: number, end?: number) → string

Parte del testo; le posizioni negative contano dalla fine.

->slice(start, end?) restituisce i caratteri dalla posizione start fino a, escluso, end, oppure fino alla fine del testo. Le posizioni negative contano dalla fine:

<let name="word" value="'teapot'" />
<echo value="$word->slice(0, 3)" /> <!-- 'tea' because it stops before position 3 -->
<echo value="$word->slice(3)" /> <!-- 'pot' -->
<echo value="$word->slice(-3)" /> <!-- 'pot' because -3 is three from the end -->
$word = 'teapot'
echo $word->slice(0, 3)   // 'tea' because it stops before position 3
echo $word->slice(3)      // 'pot'
echo $word->slice(-3)     // 'pot' because -3 is three from the end
ParametroAccetta
start requirednumber
end optionalnumber

Gli argomenti possono essere nominati: ->slice(…, end: …).

Esempio
<echo>{ 'KScript'->slice(1, 4) }</echo>
echo 'KScript'->slice(1, 4)

#string->split(separator?) → string[]

Le parti tra ogni separatore (o tra gli spazi), come lista. Il separatore può essere una regex: ->split(/\s*,\s*/).

->split(separator?) divide il testo a ogni separatore e restituisce le parti come lista. Senza separatore divide agli spazi. Il separatore può essere un'espressione regolare:

<echo value="'tea,milk,juice'->split(',')" /> <!-- ['tea', 'milk', 'juice'] -->
<echo value="'tea milk'->split()" /> <!-- ['tea', 'milk'] -->
<echo value="'a, b,c'->split(/\s*,\s*/)" /> <!-- ['a', 'b', 'c'] because the spaces around each comma go too -->
echo 'tea,milk,juice'->split(',')       // ['tea', 'milk', 'juice']
echo 'tea milk'->split()                // ['tea', 'milk']
echo 'a, b,c'->split(/\s*,\s*/)         // ['a', 'b', 'c'] because the spaces around each comma go too
Esempio
<echo>{ 'a,b,c'->split(',') }</echo>
echo 'a,b,c'->split(',')

#string->squish() → string

Il testo senza spazi iniziali e finali, con ogni sequenza di spazi, tabulazioni e a capo interni sostituita da un solo spazio.

->squish() elimina gli spazi all'inizio e alla fine del testo e trasforma ogni sequenza di spazi, tabulazioni e interruzioni di riga al suo interno in un solo spazio:

<echo value="'  too   many    spaces '->squish()" /> <!-- 'too many spaces' -->
echo '  too   many    spaces '->squish()   // 'too many spaces'
Esempio
<echo>{ '  too   many    spaces '->squish() }</echo>
echo '  too   many    spaces '->squish()

#string->starts_with(text, ignore_case?: bool) → bool

Vero quando il testo inizia con questo testo. Con ignore_case: true, maiuscole e minuscole coincidono.

->starts_with(text, ignore_case?) è vero quando il testo inizia con text:

<echo value="'https://example.com'->starts_with('https://')" /> <!-- true -->
<echo value="'HTTP://x'->starts_with('http', ignore_case)" /> <!-- true because case is ignored -->
echo 'https://example.com'->starts_with('https://')   // true
echo 'HTTP://x'->starts_with('http', ignore_case)     // true because case is ignored
ParametroAccetta
text obbligatorioqualsiasi valore
ignore_case facoltativoun flag: ignore_case oppure not ignore_case

Gli argomenti possono avere un nome: ->starts_with(…, ignore_case: …).

Esempio
<echo>{ 'kscript.json'->starts_with('kscript') }</echo>
echo 'kscript.json'->starts_with('kscript')

#string->strip(prefix?: string, suffix?: string) → string

Il testo senza un prefisso, un suffisso o entrambi esatti, dove presenti: 'v1.2'->strip(prefix: 'v'), 'a.txt'->strip(suffix: '.txt').

->strip(prefix?, suffix?) toglie un prefisso, un suffisso o entrambi esatti, dove ci sono. A differenza di ->trim(), rimuove l'intero pezzo una sola volta, non ogni carattere:

<echo value="'v1.2'->strip(prefix: 'v')" /> <!-- '1.2' -->
<echo value="'notes.txt'->strip(suffix: '.txt')" /> <!-- 'notes' -->
<echo value="'[tea]'->strip(prefix: '[', suffix: ']')" /> <!-- 'tea' -->
<echo value="'tea'->strip(prefix: 'x')" /> <!-- 'tea' because there is no x to take off -->
echo 'v1.2'->strip(prefix: 'v')                 // '1.2'
echo 'notes.txt'->strip(suffix: '.txt')         // 'notes'
echo '[tea]'->strip(prefix: '[', suffix: ']')   // 'tea'
echo 'tea'->strip(prefix: 'x')                  // 'tea' because there is no x to take off
ParametroAccetta
prefix facoltativostring
suffix facoltativostring

Gli argomenti possono avere un nome: ->strip(…, suffix: …).

Esempio
<echo>{ 'draft-notes.md'->strip(prefix: 'draft-', suffix: '.md') }</echo>
echo 'draft-notes.md'->strip(prefix: 'draft-', suffix: '.md')

#string->title() → string

Il testo in Title Case.

->title() restituisce il testo in Title Case: la prima lettera di ogni parola in maiuscolo:

<echo value="'the tea party'->title()" /> <!-- 'The Tea Party' -->
echo 'the tea party'->title()   // 'The Tea Party'
Esempio
<echo>{ 'the quick brown fox'->title() }</echo>
echo 'the quick brown fox'->title()

#string->to_base64(url?: bool) → base64

Il testo codificato in base64. Con url: true, è base64 sicuro per URL senza padding.

->to_base64(url?) codifica il testo in base64, che usa solo lettere, cifre, +, / e =, così può viaggiare dove altri caratteri non possono, come un header HTTP. Con url, usa invece - e _ e omette il padding =, così può stare in un URL. Il risultato è un valore base64, il cui ->decode() restituisce il testo originale:

<echo value="'tea'->to_base64()" /> <!-- 'dGVh' -->
<echo value="'tea?'->to_base64()" /> <!-- 'dGVhPw==' -->
<echo value="'tea?'->to_base64(url)" /> <!-- 'dGVhPw' because url leaves off the padding -->
<echo value="'tea'->to_base64()->decode()" /> <!-- 'tea' because the base64 value decodes back to the text -->
echo 'tea'->to_base64()                 // 'dGVh'
echo 'tea?'->to_base64()                // 'dGVhPw=='
echo 'tea?'->to_base64(url)             // 'dGVhPw' because url leaves off the padding
echo 'tea'->to_base64()->decode()       // 'tea' because the base64 value decodes back to the text
ParametroAccetta
url facoltativoun flag: url oppure not url
Esempio
<echo>{ 'hello'->to_base64() }</echo>
echo 'hello'->to_base64()

#string->to_bool() → bool

Testo come 'true', 'false', 'yes', 'no', '1' o '0' come bool.

->to_bool() legge testi come 'true', 'false', 'yes', 'no', '1' o '0' come bool. Ogni altro testo genera un errore di tipo:

<echo value="'yes'->to_bool()" /> <!-- true -->
<echo value="'0'->to_bool()" /> <!-- false -->
echo 'yes'->to_bool()    // true
echo '0'->to_bool()      // false
Esempio
<echo>{ 'yes'->to_bool() }</echo>
echo 'yes'->to_bool()

#string->to_date(format?: date_format) → date

Legge il testo come data: '2026-11-22'->to_date(), oppure, con il formato in cui è scritto, '22-11-2026'->to_date(dd-MM-yyyy).

->to_date(format?) legge il testo come data. Le date scritte in formato ISO, come '2026-11-22' o '2026-11-22 14:30', non richiedono un formato; per ogni altro formato, indica il pattern in cui è scritta:

<let name="day" value="'2026-11-22'->to_date()" />
<echo value="$day.year" /> <!-- 2026 -->
<echo value="'22-11-2026'->to_date(dd-MM-yyyy).month" /> <!-- 11 because the pattern says the month is in the middle -->
$day = '2026-11-22'->to_date()
echo $day.year                                // 2026
echo '22-11-2026'->to_date(dd-MM-yyyy).month  // 11 because the pattern says the month is in the middle
ParametroAccetta
format facoltativodate_format
Esempio
<echo>{ '2026-11-19'->to_date().weekday }</echo>
echo '2026-11-19'->to_date().weekday

#string->to_int(default?) → number

Il testo come numero intero, oppure default se non lo è.

->to_int(default?) legge il testo come numero intero, scartando tutto ciò che segue il punto decimale. Quando il testo non è un numero, ottieni default; senza un valore di default, è un errore di tipo, quindi passa un default per i testi di cui non sei sicuro:

<echo value="'42'->to_int()" /> <!-- 42 -->
<echo value="'3.7'->to_int()" /> <!-- 3 because the .7 is dropped -->
<echo value="'abc'->to_int(-1)" /> <!-- -1 because abc isn't a number -->
echo '42'->to_int()        // 42
echo '3.7'->to_int()       // 3 because the .7 is dropped
echo 'abc'->to_int(-1)     // -1 because abc isn't a number
Esempio
<echo>{ '42'->to_int() + 1 }</echo>
echo '42'->to_int() + 1

#string->to_number(default?) → number

Il testo come numero, oppure default se non lo è.

->to_number(default?) legge il testo come numero, decimali compresi. Quando il testo non è un numero, ottieni default; senza un valore di default, è un errore di tipo che lo segnala:

<echo value="'3.7'->to_number()" /> <!-- 3.7 -->
<echo value="'x'->to_number(0)" /> <!-- 0 because x isn't a number, so the default is used -->
<echo value="'x'->to_number(null)" /> <!-- null -->
echo '3.7'->to_number()      // 3.7
echo 'x'->to_number(0)       // 0 because x isn't a number, so the default is used
echo 'x'->to_number(null)    // null
Esempio
<echo>{ '3.5'->to_number() * 2 }</echo>
echo '3.5'->to_number() * 2

#string->trim(characters?, start?: bool, end?: bool) → string

Il testo senza spazi (o i caratteri indicati) a una o entrambe le estremità, oppure solo all'inizio o alla fine: ->trim(start), ->trim('/', end).

->trim(characters?, start?, end?) rimuove spazi, tabulazioni e interruzioni di riga da entrambe le estremità, oppure i caratteri che indichi. Con start o end taglia solo quel lato:

<echo value="'  tea  '->trim()" /> <!-- 'tea' -->
<echo value="'//path//'->trim('/')" /> <!-- 'path' -->
<echo value="'  tea  '->trim(start)" /> <!-- 'tea  ' because only the start is trimmed -->
echo '  tea  '->trim()           // 'tea'
echo '//path//'->trim('/')       // 'path'
echo '  tea  '->trim(start)      // 'tea  ' because only the start is trimmed
ParametroAccetta
characters facoltativoqualsiasi valore
start facoltativoun flag: start o not start
end optionalun flag: end oppure not end

Gli argomenti possono avere un nome: ->trim(…, start: …, end: …).

Esempio
<echo>{ '  hello  '->trim() + '!' }</echo>
echo '  hello  '->trim() + '!'

#string->truncate(length: number, suffix?) → string

Accorcia il testo a length, aggiungendo suffix (… per impostazione predefinita).

->truncate(length, suffix?) mantiene i primi length caratteri e aggiunge un suffisso, … salvo che tu ne indichi un altro, se c'era di più. Il testo che già rientra resta invariato:

<echo value="'Hello there, friend'->truncate(10)" /> <!-- 'Hello ther…' -->
<echo value="'Hello there, friend'->truncate(10, '...')" /> <!-- 'Hello ther...' -->
<echo value="'Hi'->truncate(10)" /> <!-- 'Hi' because it already fits -->
echo 'Hello there, friend'->truncate(10)          // 'Hello ther…'
echo 'Hello there, friend'->truncate(10, '...')   // 'Hello ther...'
echo 'Hi'->truncate(10)                           // 'Hi' because it already fits
ParametroAccetta
length obbligatorionumber
suffix facoltativoqualsiasi valore

Gli argomenti possono avere un nome: ->truncate(…, suffix: …).

Esempio
<echo>{ 'A long sentence about nothing'->truncate(12) }</echo>
echo 'A long sentence about nothing'->truncate(12)

#string->upper() → string

Il testo in maiuscolo.

->upper() restituisce il testo in maiuscolo:

<echo value="'Green tea'->upper()" /> <!-- 'GREEN TEA' -->
echo 'Green tea'->upper()   // 'GREEN TEA'
Esempio
<echo>{ 'hello'->upper() }</echo>
echo 'hello'->upper()

#string->url_decode() → string

Testo con codifica URL decodificato.

->url_decode() riconverte le sequenze di escape URL come %20 nei caratteri che rappresentano:

<echo value="'tea%20%26%20milk'->url_decode()" /> <!-- 'tea & milk' -->
echo 'tea%20%26%20milk'->url_decode()   // 'tea & milk'
Esempio
<echo>{ 'a%20b%2Fc'->url_decode() }</echo>
echo 'a%20b%2Fc'->url_decode()

#string->url_encode() → string

Il testo codificato per un URL.

->url_encode() applica l'escape al testo così che sia sicuro in un URL, ad esempio un termine di ricerca in una query string:

<echo value="'tea &amp; milk'->url_encode()" /> <!-- 'tea%20%26%20milk' because spaces and & have a meaning in URLs -->
echo 'tea & milk'->url_encode()   // 'tea%20%26%20milk' because spaces and & have a meaning in URLs
Esempio
<echo>{ 'a b/c?d'->url_encode() }</echo>
echo 'a b/c?d'->url_encode()

#string->words() → string[]

Le parole del testo, come lista, senza spazi né punteggiatura. Contano le lettere di qualsiasi alfabeto, e don't o well-known sono una sola parola.

->words() restituisce le parole del testo, senza gli spazi e la punteggiatura tra di esse. Contano le lettere di qualsiasi alfabeto, e don't o well-known restano una sola parola:

<echo value="'Hello, world!'->words()" /> <!-- ['Hello', 'world'] -->
<echo value="&quot;Don't stop&quot;->words()->count()" /> <!-- 2 because don't is one word -->
echo 'Hello, world!'->words()           // ['Hello', 'world']
echo "Don't stop"->words()->count()     // 2 because don't is one word
Esempio
<echo>{ 'Hello, world! A well-known phrase.'->words() }</echo>
echo 'Hello, world! A well-known phrase.'->words()

#string->wrap(width: number) → string

Il testo con interruzioni di riga tra le parole, in modo che nessuna riga superi width (a meno che una singola parola non sia più lunga). Funziona bene con @terminal_width().

->wrap(width) inserisce interruzioni di riga tra le parole in modo che nessuna riga superi width, a meno che una singola parola non sia più lunga. È adatto al testo per un terminale, come uno largo @terminal_width():

<let name="lines" value="'Ann went home early'->wrap(width: 9)->lines()" />
<echo value="$lines" /> <!-- ['Ann went', 'home', 'early'] because home early would be 10 characters -->
$lines = 'Ann went home early'->wrap(width: 9)->lines()
echo $lines   // ['Ann went', 'home', 'early'] because home early would be 10 characters
ParametroAccetta
width obbligatorionumber
Esempio
<echo>{ 'The quick brown fox jumps over the lazy dog'->wrap(width: 15)->lines() }</echo>
echo 'The quick brown fox jumps over the lazy dog'->wrap(width: 15)->lines()

Da KScript.Markdown

Questi richiedono <import package="KScript.Markdown" />import KScript.Markdown. Vedi KScript.Markdown.

#string->markdown_escape() → string KScript.Markdown

Il testo con escape, così che Markdown lo mostri così come è scritto.
Esempio
<import package="KScript.Markdown" />
<echo>{ '2 * 3 = 6'->markdown_escape() }</echo>
import KScript.Markdown
echo '2 * 3 = 6'->markdown_escape()

Metodi da any

Metodi da number