Funzioni stringa
| Nome | Descrizione |
BYTE_LENGTH
|
Restituisce il numero di BYTES in un valore STRING o BYTES
|
CHAR_LENGTH
|
Restituisce il numero di caratteri Unicode in un valore STRING
|
STARTS_WITH
|
Restituisce TRUE se un STRING inizia con un determinato prefisso
|
ENDS_WITH
|
Restituisce TRUE se un STRING termina con un determinato suffisso
|
LIKE
|
Restituisce TRUE se un STRING corrisponde a un pattern
|
REGEX_CONTAINS
|
Restituisce TRUE se un valore corrisponde parzialmente o completamente a un'espressione regolare
|
REGEX_MATCH
|
Restituisce TRUE se una parte di un valore corrisponde a un'espressione regolare
|
STRING_CONCAT
|
Concatena più STRING in un STRING
|
STRING_CONTAINS
|
Restituisce TRUE se un valore contiene STRING
|
STRING_INDEX_OF
|
Restituisce l'indice in base zero della prima occorrenza di un valore STRING o BYTES.
|
TO_UPPER
|
Converte un valore STRING o BYTES in maiuscolo.
|
TO_LOWER
|
Converte un valore STRING o BYTES in minuscolo.
|
SUBSTRING
|
Ottiene una sottostringa di un valore STRING o BYTES.
|
STRING_REVERSE
|
Inverte un valore STRING o BYTES.
|
STRING_REPEAT
|
Ripete un valore STRING o BYTES un numero specificato di volte.
|
STRING_REPLACE_ALL
|
Sostituisce tutte le occorrenze di un valore STRING o BYTES.
|
STRING_REPLACE_ONE
|
Sostituisce la prima occorrenza di un valore STRING o BYTES.
|
TRIM
|
Rimuove i caratteri iniziali e finali da un valore STRING o BYTES.
|
LTRIM
|
Taglia i caratteri iniziali da un valore STRING o BYTES.
|
RTRIM
|
Taglia i caratteri finali da un valore STRING o BYTES.
|
SPLIT
|
Divide un valore STRING o BYTES in un array.
|
BYTE_LENGTH
Sintassi:
byte_length[T <: STRING | BYTES](value: T) -> INT64
Descrizione:
Restituisce il numero di BYTES in un valore STRING o BYTES.
Esempi:
| valore | byte_length(value) |
|---|---|
| "abc" | 3 |
| "xyzabc" | 6 |
| b"abc" | 3 |
Node.js
const result = await db.pipeline() .collection("books") .select( field("title").byteLength().as("titleByteLength") ) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select( field("title").byteLength().as("titleByteLength") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("title").byteLength().as("titleByteLength") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( field("title").byteLength().alias("titleByteLength") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("title").byteLength().alias("titleByteLength") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("title").byte_length().as_("titleByteLength")) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(byteLength(field("title")).as("titleByteLength")) .execute() .get();
CHAR_LENGTH
Sintassi:
char_length(value: STRING) -> INT64
Descrizione:
Restituisce il numero di punti di codice Unicode nel valore STRING.
Esempi:
| valore | char_length(value) |
|---|---|
| "abc" | 3 |
| "ciao" | 5 |
| "world" | 5 |
Node.js
const result = await db.pipeline() .collection("books") .select( field("title").charLength().as("titleCharLength") ) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select( field("title").charLength().as("titleCharLength") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("title").charLength().as("titleCharLength") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( field("title").charLength().alias("titleCharLength") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("title").charLength().alias("titleCharLength") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("title").char_length().as_("titleCharLength")) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(charLength(field("title")).as("titleCharLength")) .execute() .get();
STARTS_WITH
Sintassi:
starts_with(value: STRING, prefix: STRING) -> BOOLEAN
Descrizione:
Restituisce TRUE se value inizia con prefix.
Esempi:
| valore | prefisso | starts_with(value, prefix) |
|---|---|---|
| "abc" | "a" | true |
| "abc" | "b" | falso |
| "abc" | "" | true |
Node.js
const result = await db.pipeline() .collection("books") .select( field("title").startsWith("The") .as("needsSpecialAlphabeticalSort") ) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select( field("title").startsWith("The") .as("needsSpecialAlphabeticalSort") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("title").startsWith("The") .as("needsSpecialAlphabeticalSort") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( field("title").startsWith("The") .alias("needsSpecialAlphabeticalSort") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("title").startsWith("The") .alias("needsSpecialAlphabeticalSort") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select( Field.of("title").starts_with("The").as_("needsSpecialAlphabeticalSort") ) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(startsWith(field("title"), "The").as("needsSpecialAlphabeticalSort")) .execute() .get();
ENDS_WITH
Sintassi:
ends_with(value: STRING, postfix: STRING) -> BOOLEAN
Descrizione:
Restituisce TRUE se value termina con postfix.
Esempi:
| valore | suffisso | ends_with(value, postfix) |
|---|---|---|
| "abc" | "c" | true |
| "abc" | "b" | falso |
| "abc" | "" | true |
Node.js
const result = await db.pipeline() .collection("inventory/devices/laptops") .select( field("name").endsWith("16 inch") .as("16InLaptops") ) .execute();
Swift
let result = try await db.pipeline() .collection("inventory/devices/laptops") .select([ Field("name").endsWith("16 inch") .as("16InLaptops") ]) .execute()
Kotlin
val result = db.pipeline() .collection("inventory/devices/laptops") .select( field("name").endsWith("16 inch") .alias("16InLaptops") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("inventory/devices/laptops") .select( field("name").endsWith("16 inch") .alias("16InLaptops") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("inventory/devices/laptops") .select(Field.of("name").ends_with("16 inch").as_("16InLaptops")) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("inventory/devices/laptops") .select(endsWith(field("name"), "16 inch").as("16InLaptops")) .execute() .get();
MI PIACE
Sintassi:
like(value: STRING, pattern: STRING) -> BOOLEAN
Descrizione:
Restituisce TRUE se value corrisponde a pattern.
Esempi:
| valore | motivo | like(value, pattern) |
|---|---|---|
| "Firestore" | "Fire%" | true |
| "Firestore" | "%store" | true |
| "Datastore" | "Data_tore" | true |
| "100%" | "100%" | true |
Node.js
const result = await db.pipeline() .collection("books") .select( field("genre").like("%Fiction") .as("anyFiction") ) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select( field("genre").like("%Fiction") .as("anyFiction") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("genre").like("%Fiction") .as("anyFiction") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( field("genre").like("%Fiction") .alias("anyFiction") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("genre").like("%Fiction") .alias("anyFiction") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("genre").like("%Fiction").as_("anyFiction")) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(like(field("genre"), "%Fiction").as("anyFiction")) .execute() .get();
REGEX_CONTAINS
Sintassi:
regex_contains(value: STRING, pattern: STRING) -> BOOLEAN
Descrizione:
Restituisce TRUE se una parte di value corrisponde a pattern. Se pattern non è un'espressione regolare valida, questa funzione restituisce error.
Le espressioni regolari seguono la sintassi della libreria re2.
Esempi:
| valore | motivo | regex_contains(value, pattern) |
|---|---|---|
| "Firestore" | "Fuoco" | true |
| "Firestore" | "store$" | true |
| "Firestore" | "dati" | falso |
Node.js
const result = await db.pipeline() .collection("documents") .select( field("title").regexContains("Firestore (Enterprise|Standard)") .as("isFirestoreRelated") ) .execute();
Web
const result = await execute(db.pipeline() .collection("documents") .select( field("title").regexContains("Firestore (Enterprise|Standard)") .as("isFirestoreRelated") ) );
Swift
let result = try await db.pipeline() .collection("documents") .select([ Field("title").regexContains("Firestore (Enterprise|Standard)") .as("isFirestoreRelated") ]) .execute()
Kotlin
val result = db.pipeline() .collection("documents") .select( field("title").regexContains("Firestore (Enterprise|Standard)") .alias("isFirestoreRelated") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("documents") .select( field("title").regexContains("Firestore (Enterprise|Standard)") .alias("isFirestoreRelated") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("documents") .select( Field.of("title") .regex_contains("Firestore (Enterprise|Standard)") .as_("isFirestoreRelated") ) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("documents") .select( regexContains(field("title"), "Firestore (Enterprise|Standard)") .as("isFirestoreRelated")) .execute() .get();
REGEX_MATCH
Sintassi:
regex_match(value: STRING, pattern: STRING) -> BOOLEAN
Descrizione:
Restituisce TRUE se value corrisponde esattamente a pattern. Se pattern non è un'espressione regolare valida, questa funzione restituisce error.
Le espressioni regolari seguono la sintassi della libreria re2.
Esempi:
| valore | motivo | regex_match(value, pattern) |
|---|---|---|
| "Firestore" | "F.*store" | true |
| "Firestore" | "Fuoco" | falso |
| "Firestore" | "^F.*e$" | true |
Node.js
const result = await db.pipeline() .collection("documents") .select( field("title").regexMatch("Firestore (Enterprise|Standard)") .as("isFirestoreExactly") ) .execute();
Web
const result = await execute(db.pipeline() .collection("documents") .select( field("title").regexMatch("Firestore (Enterprise|Standard)") .as("isFirestoreExactly") ) );
Swift
let result = try await db.pipeline() .collection("documents") .select([ Field("title").regexMatch("Firestore (Enterprise|Standard)") .as("isFirestoreExactly") ]) .execute()
Kotlin
val result = db.pipeline() .collection("documents") .select( field("title").regexMatch("Firestore (Enterprise|Standard)") .alias("isFirestoreExactly") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("documents") .select( field("title").regexMatch("Firestore (Enterprise|Standard)") .alias("isFirestoreExactly") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("documents") .select( Field.of("title") .regex_match("Firestore (Enterprise|Standard)") .as_("isFirestoreExactly") ) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("documents") .select( regexMatch(field("title"), "Firestore (Enterprise|Standard)") .as("isFirestoreExactly")) .execute() .get();
STRING_CONCAT
Sintassi:
string_concat(values: STRING...) -> STRING
Descrizione:
Concatena due o più valori STRING in un unico risultato.
Esempi:
| argomenti | string_concat(values...) |
|---|---|
() |
errore |
("a") |
"a" |
("abc", "def") |
"abcdef" |
("a", "", "c") |
"ac" |
Node.js
const result = await db.pipeline() .collection("books") .select( field("title").stringConcat(" by ", field("author")) .as("fullyQualifiedTitle") ) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select( field("title").stringConcat(" by ", field("author")) .as("fullyQualifiedTitle") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("title").concat([" by ", Field("author")]) .as("fullyQualifiedTitle") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( field("title").concat(" by ", field("author")) .alias("fullyQualifiedTitle") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("title").concat(" by ", field("author")) .alias("fullyQualifiedTitle") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select( Field.of("title") .concat(" by ", Field.of("author")) .as_("fullyQualifiedTitle") ) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(stringConcat(field("title"), " by ", field("author")).as("fullyQualifiedTitle")) .execute() .get();
STRING_CONTAINS
Sintassi:
string_contains(value: STRING, substring: STRING) -> BOOLEAN
Descrizione:
Controlla se value contiene la stringa letterale substring.
Esempi:
| valore | substring | string_contains(value, substring) |
|---|---|---|
| "abc" | "b" | true |
| "abc" | "d" | falso |
| "abc" | "" | true |
| "a.c" | "." | true |
| "☃☃☃" | "☃" | true |
Node.js
const result = await db.pipeline() .collection("articles") .select( field("body").stringContains("Firestore") .as("isFirestoreRelated") ) .execute();
Web
const result = await execute(db.pipeline() .collection("articles") .select( field("body").stringContains("Firestore") .as("isFirestoreRelated") ) );
Swift
let result = try await db.pipeline() .collection("articles") .select([ Field("body").stringContains("Firestore") .as("isFirestoreRelated") ]) .execute()
Kotlin
val result = db.pipeline() .collection("articles") .select( field("body").stringContains("Firestore") .alias("isFirestoreRelated") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("articles") .select( field("body").stringContains("Firestore") .alias("isFirestoreRelated") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("articles") .select(Field.of("body").string_contains("Firestore").as_("isFirestoreRelated")) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("articles") .select(stringContains(field("body"), "Firestore").as("isFirestoreRelated")) .execute() .get();
STRING_INDEX_OF
Sintassi:
string_index_of[T <: STRING | BYTES](value: T, search: T) -> INT64
Descrizione:
Restituisce l'indice a base 0 della prima occorrenza di search in value.
- Restituisce
-1sesearchnon viene trovato. - Se
valueè un valoreSTRING, il risultato viene misurato in punti di codice Unicode. Se si tratta di un valoreBYTES, viene misurato in byte. - Se
searchè un valoreSTRINGoBYTESvuoto, il risultato è0.
Esempi:
| valore | search | string_index_of(value, search) |
|---|---|---|
| "hello world" | "o" | 4 |
| "hello world" | "l" | 2 |
| "hello world" | "z" | -1 |
| "banana" | "na" | 2 |
| "abc" | "" | 0 |
| b"abc" | b"b" | 1 |
| "é" | "é" | 0 |
| b"é" | b"é" | 0 |
TO_UPPER
Sintassi:
to_upper[T <: STRING | BYTES](value: T) -> T
Descrizione:
Converte un valore STRING o BYTES in maiuscolo.
Se un byte o un carattere non corrisponde a un carattere alfabetico minuscolo UTF-8, viene passato invariato.
Esempi:
| valore | to_upper(value) |
|---|---|
| "abc" | "ABC" |
| "AbC" | "ABC" |
| b"abc" | b"ABC" |
| b"a1c" | b"A1C" |
Node.js
const result = await db.pipeline() .collection("authors") .select( field("name").toUpper() .as("uppercaseName") ) .execute();
Web
const result = await execute(db.pipeline() .collection("authors") .select( field("name").toUpper() .as("uppercaseName") ) );
Swift
let result = try await db.pipeline() .collection("authors") .select([ Field("name").toUpper() .as("uppercaseName") ]) .execute()
Kotlin
val result = db.pipeline() .collection("authors") .select( field("name").toUpper() .alias("uppercaseName") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("authors") .select( field("name").toUpper() .alias("uppercaseName") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("authors") .select(Field.of("name").to_upper().as_("uppercaseName")) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("authors") .select(toUpper(field("name")).as("uppercaseName")) .execute() .get();
TO_LOWER
Sintassi:
to_lower[T <: STRING | BYTES](value: T) -> T
Descrizione:
Converte un valore STRING o BYTES in minuscolo.
Se un byte o un carattere non corrisponde a un carattere alfabetico maiuscolo UTF-8, viene passato invariato.
Esempi:
| valore | to_lower(value) |
|---|---|
| "ABC" | "abc" |
| "AbC" | "abc" |
| "A1C" | "a1c" |
| b"ABC" | b"abc" |
Node.js
const result = await db.pipeline() .collection("authors") .select( field("genre").toLower().equal("fantasy") .as("isFantasy") ) .execute();
Web
const result = await execute(db.pipeline() .collection("authors") .select( field("genre").toLower().equal("fantasy") .as("isFantasy") ) );
Swift
let result = try await db.pipeline() .collection("authors") .select([ Field("genre").toLower().equal("fantasy") .as("isFantasy") ]) .execute()
Kotlin
val result = db.pipeline() .collection("authors") .select( field("genre").toLower().equal("fantasy") .alias("isFantasy") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("authors") .select( field("genre").toLower().equal("fantasy") .alias("isFantasy") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("authors") .select(Field.of("genre").to_lower().equal("fantasy").as_("isFantasy")) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("authors") .select(equal(toLower(field("genre")), "fantasy").as("isFantasy")) .execute() .get();
SUBSTRING
Sintassi:
substring[T <: STRING | BYTES](input: T, position: INT64) -> T
substring[T <: STRING | BYTES](input: T, position: INT64, length: INT64) -> T
Descrizione:
Restituisce una sottostringa di input a partire da position (indice in base zero) e
includendo fino a length voci. Se non viene fornito alcun length, restituisce la sottostringa
da position alla fine di input.
Se
inputè un valoreSTRING,positionelengthvengono misurati in punti di codice Unicode. Se si tratta di un valoreBYTES, vengono misurati in byte.Se
positionè maggiore della lunghezza diinput, viene restituita una sottostringa vuota. Sepositionpiùlengthè maggiore della lunghezza diinput, la sottostringa viene troncata alla fine diinput.Se
positionè negativo, la posizione viene presa dalla fine dell'input. Se il valore negativo dipositionè maggiore della dimensione dell'input, la posizione viene impostata su zero.lengthnon deve essere un valore negativo.
Esempi:
Quando length non viene fornito:
| immissione | position | substring(input, position) |
|---|---|---|
| "abc" | 0 | "abc" |
| "abc" | 1 | "bc" |
| "abc" | 3 | "" |
| "abc" | -1 | "c" |
| b"abc" | 1 | b"bc" |
Quando viene fornito length:
| immissione | position | lunghezza | substring(input, position, length) |
|---|---|---|---|
| "abc" | 0 | 1 | "a" |
| "abc" | 1 | 2 | "bc" |
| "abc" | -1 | 1 | "c" |
| b"abc" | 0 | 1 | b"a" |
Node.js
const result = await db.pipeline() .collection("books") .where(field("title").startsWith("The ")) .select( field("title").substring(4) .as("titleWithoutLeadingThe") ) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .where(field("title").startsWith("The ")) .select( field("title").substring(4) .as("titleWithoutLeadingThe") ) );
Swift
let result = try await db.pipeline() .collection("books") .where(Field("title").startsWith("The ")) .select([ Field("title").substring(position: 4) .as("titleWithoutLeadingThe") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .where(field("title").startsWith("The ")) .select( field("title") .substring(constant(4), field("title").charLength().subtract(4)) .alias("titleWithoutLeadingThe") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .where(field("title").startsWith("The ")) .select( field("title").substring( constant(4), field("title").charLength().subtract(4)) .alias("titleWithoutLeadingThe") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .where(Field.of("title").starts_with("The ")) .select(Field.of("title").substring(4).as_("titleWithoutLeadingThe")) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .where(startsWith(field("title"), "The ")) .select( substring(field("title"), constant(4), field("title").charLength()) .as("titleWithoutLeadingThe")) .execute() .get();
STRING_REVERSE
Sintassi:
string_reverse[T <: STRING | BYTES](input: T) -> T
Descrizione:
Restituisce l'input fornito in ordine inverso.
I caratteri sono delimitati dai punti di codice Unicode quando l'input è un STRING e dai byte quando l'input è un valore BYTES.
Esempi:
| immissione | string_reverse(input) |
|---|---|
| "abc" | "cba" |
| "a🌹b" | "b🌹a" |
| "ciao" | "olleh" |
| b"abc" | b"cba" |
Node.js
const result = await db.pipeline() .collection("books") .select( field("name").reverse().as("reversedName") ) .execute();
Web
const result = await execute(db.pipeline() .collection("books") .select( field("name").reverse().as("reversedName") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("name").reverse().as("reversedName") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( field("name").reverse().alias("reversedName") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("name").reverse().alias("reversedName") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("name").string_reverse().as_("reversedName")) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(reverse(field("name")).as("reversedName")) .execute() .get();
STRING_REPEAT
Sintassi:
string_repeat[T <: STRING | BYTES](input: T, repetitions: INT64) -> T
Descrizione:
Restituisce input ripetuto repetitions volte.
repetitionsdeve essere un numero intero non negativo.- Se
repetitionsè0, restituisce un valore vuoto dello stesso tipo diinput. - Se il risultato supera la dimensione massima consentita (1 MB), viene restituito un errore.
Esempi:
| immissione | ripetizioni | string_repeat(input, repetitions) |
|---|---|---|
| "foo" | 3 | "foofoofoo" |
| "foo" | 0 | "" |
| "a " | 3 | "a a a " |
| b"ab" | 2 | b"abab" |
| "é🦆" | 2 | "é🦆é🦆" |
STRING_REPLACE_ALL
Sintassi:
string_replace_all[T <: STRING | BYTES](input: T, find: T, replacement: T) -> T
Descrizione:
Sostituisce tutte le occorrenze non sovrapposte di find in input con replacement.
- Le corrispondenze sono sensibili alle maiuscole.
- Se
findè vuoto, non vengono effettuate sostituzioni.
Esempi:
| immissione | find | sostituzione | string_replace_all(input, find, replacement) |
|---|---|---|---|
| "foobarfoo" | "foo" | "baz" | "bazbarbaz" |
| "ababab" | "aba" | "c" | "cbab" |
| "foobar" | "o" | "" | "fbar" |
| "é🦆🌎🦆" | "🦆" | "a" | "éa🌎a" |
| b"abc" | b"b" | b"d" | b"adc" |
STRING_REPLACE_ONE
Sintassi:
string_replace_one[T <: STRING | BYTES](input: T, find: T, replacement: T) -> T
Descrizione:
Sostituisce la prima occorrenza di find in input con replacement.
- Le corrispondenze sono sensibili alle maiuscole.
- Se
findè vuoto, non vengono effettuate sostituzioni.
Esempi:
| immissione | find | sostituzione | string_replace_one(input, find, replacement) |
|---|---|---|---|
| "foobarfoo" | "foo" | "baz" | "bazbarfoo" |
| "é" | "é" | "a" | "a" |
| b"foobar" | b"o" | b"z" | b"fzoobar" |
TRIM
Sintassi:
trim[T <: STRING | BYTES](input: T, values_to_trim: T) -> T
trim[T <: STRING | BYTES](input: T) -> T
Descrizione:
Elimina un insieme specificato di BYTES o CHARS dall'inizio e dalla fine del
input fornito.
- Se non vengono forniti
values_to_trim, vengono eliminati gli spazi vuoti.
Esempi:
Quando values_to_trim non viene fornito:
| immissione | trim(input) |
|---|---|
| " foo " | "foo" |
| b" foo " | b"foo" |
| "foo" | "foo" |
| "" | "" |
| " " | "" |
| "\t foo \n" | "foo" |
| b"\t foo \n" | b"foo" |
| "\r\f\v foo \r\f\v" | "foo" |
| b"\r\f\v foo \r\f\v" | b"foo" |
Quando viene fornito values_to_trim:
| immissione | values_to_trim | trim(input, values_to_trim) |
|---|---|---|
| "abcbfooaacb" | "abc" | "foo" |
| "abcdaabadbac" | "abc" | "daabad" |
| b"C1C2C3" | b"C1" | b"C2C3" |
| b"C1C2" | "foo" | errore |
| "foo" | b"C1" | errore |
Web
const result = await execute(db.pipeline() .collection("books") .select( field("name").trim().as("whitespaceTrimmedName") ) );
Swift
let result = try await db.pipeline() .collection("books") .select([ Field("name").trim(" \n\t").as("whitespaceTrimmedName") ]) .execute()
Kotlin
val result = db.pipeline() .collection("books") .select( field("name").trim().alias("whitespaceTrimmedName") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select( field("name").trim().alias("whitespaceTrimmedName") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("name").trim().as_("whitespaceTrimmedName")) .execute() )
Java
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(trim(field("name")).as("whitespaceTrimmedName")) .execute() .get();
LTRIM
Sintassi:
ltrim[T <: STRING | BYTES](value: T, to_trim: T) -> T
ltrim[T <: STRING | BYTES](value: T) -> T
Descrizione:
Taglia un insieme specificato di BYTES o CHARS dall'inizio del value fornito.
- Se
to_trimnon viene fornito, vengono rimossi gli spazi vuoti iniziali.
Esempi:
Quando to_trim non viene fornito:
| valore | ltrim(value) |
|---|---|
| " foo " | "foo " |
| "foo" | "foo" |
Quando viene fornito to_trim:
| valore | to_trim | ltrim(value, to_trim) |
|---|---|---|
| "aaabc" | "a" | "bc" |
| "abacaba" | "ba" | "caba" |
| "é" | "é" | "" |
RTRIM
Sintassi:
rtrim[T <: STRING | BYTES](value: T, to_trim: T) -> T
rtrim[T <: STRING | BYTES](value: T) -> T
Descrizione:
Taglia un insieme specificato di BYTES o CHARS dalla fine di value fornito.
- Se
to_trimnon viene fornito, vengono rimossi gli spazi vuoti finali.
Esempi:
Quando to_trim non viene fornito:
| valore | rtrim(value) |
|---|---|
| " foo " | " foo" |
| "foo" | "foo" |
Quando viene fornito to_trim:
| valore | to_trim | rtrim(value, to_trim) |
|---|---|---|
| "abccc" | "c" | "ab" |
| "abacaba" | "ba" | "abac" |
| "é" | "é" | "" |
DIVIDI
Sintassi:
split(input: STRING) -> ARRAY<STRING>
split[T <: STRING | BYTES](input: T, delimiter: T) -> ARRAY<T>
Descrizione:
Divide un valore STRING o BYTES utilizzando un delimitatore.
Per
STRING, il delimitatore predefinito è la virgola,. Il delimitatore viene trattato come una singola stringa.Per
BYTES, devi specificare un delimitatore.La suddivisione in base a un delimitatore vuoto produce una matrice di punti di codice Unicode per i valori
STRINGe una matrice diBYTESper i valoriBYTES.La suddivisione di un
STRINGvuoto restituisce unARRAYcon un singoloSTRINGvuoto.
Esempi:
Quando delimiter non viene fornito:
| immissione | split(input) |
|---|---|
| "foo,bar,foo" | ["foo", "bar", "foo"] |
| "foo" | ["foo"] |
| ",foo," | ["", "foo", ""] |
| "" | [""] |
| b"C120C2C4" | errore |
Quando viene fornito delimiter:
| immissione | delimitatore | split(input, delimiter) |
|---|---|---|
| "foo bar foo" | " " | ["foo", "bar", "foo"] |
| "foo bar foo" | "z" | ["foo bar foo"] |
| "abc" | "" | ["a", "b", "c"] |
| b"C1,C2,C4" | b"," | [b"C1", b"C2", b"C4"] |
| b"ABC" | b"" | [b"A", b"B", b"C"] |
| "foo" | b"C1" | errore |