توابع رشتهای
| نام | توضیحات |
BYTE_LENGTH | تعداد BYTES در یک مقدار STRING یا BYTES را برمیگرداند. |
CHAR_LENGTH | تعداد کاراکترهای یونیکد در یک مقدار STRING را برمیگرداند |
STARTS_WITH | اگر یک STRING با پیشوند داده شده شروع شود، TRUE را برمیگرداند. |
ENDS_WITH | اگر یک STRING با پسوند مشخص شده پایان یابد TRUE را برمیگرداند. |
LIKE | اگر یک STRING با الگو مطابقت داشته باشد، TRUE را برمیگرداند. |
REGEX_CONTAINS | اگر مقداری با یک عبارت منظم مطابقت جزئی یا کامل داشته باشد، TRUE را برمیگرداند. |
REGEX_MATCH | اگر هر بخشی از یک مقدار با یک عبارت منظم مطابقت داشته باشد، TRUE برمیگرداند. |
STRING_CONCAT | چندین STRING به هم متصل کرده و یک STRING ایجاد میکند. |
STRING_CONTAINS | اگر مقدار شامل یک STRING باشد، TRUE برمیگرداند. |
TO_UPPER | یک مقدار STRING یا BYTES را به حروف بزرگ تبدیل میکند. |
TO_LOWER | یک مقدار STRING یا BYTES را به حروف کوچک تبدیل میکند. |
SUBSTRING | یک زیررشته از یک مقدار STRING یا BYTES دریافت میکند. |
STRING_REVERSE | مقدار STRING یا BYTES را معکوس میکند. |
TRIM | کاراکترهای اول و آخر یک مقدار STRING یا BYTES را حذف میکند. |
SPLIT | یک مقدار STRING یا BYTES را به یک آرایه تقسیم میکند. |
طول بایت
نحو:
byte_length[T <: STRING | BYTES](value: T) -> INT64
شرح:
تعداد BYTES در یک مقدار STRING یا BYTES را برمیگرداند.
مثالها:
| ارزش | byte_length(value) |
|---|---|
| "ای بی سی" | ۳ |
| "xyzabc" | ۶ |
| ب"الفبا" | ۳ |
Web
const result = await execute(db.pipeline() .collection("books") .select( field("title").byteLength().as("titleByteLength") ) );
سویفت
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();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("title").byte_length().as_("titleByteLength")) .execute() )
طول کاراکتر
نحو:
char_length(value: STRING) -> INT64
شرح:
تعداد نقاط کد یونیکد را در مقدار STRING برمیگرداند.
مثالها:
| ارزش | char_length(value) |
|---|---|
| "ای بی سی" | ۳ |
| «سلام» | ۵ |
| «جهان» | ۵ |
Web
const result = await execute(db.pipeline() .collection("books") .select( field("title").charLength().as("titleCharLength") ) );
سویفت
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();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("title").char_length().as_("titleCharLength")) .execute() )
شروع_با
نحو:
starts_with(value: STRING, prefix: STRING) -> BOOLEAN
شرح:
اگر value با prefix شروع شود، TRUE برمیگرداند.
مثالها:
| ارزش | پیشوند | starts_with(value, prefix) |
|---|---|---|
| "ای بی سی" | «الف» | درست |
| "ای بی سی" | «ب» | نادرست |
| "ای بی سی" | «» | درست |
Web
const result = await execute(db.pipeline() .collection("books") .select( field("title").startsWith("The") .as("needsSpecialAlphabeticalSort") ) );
سویفت
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();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select( Field.of("title").starts_with("The").as_("needsSpecialAlphabeticalSort") ) .execute() )
پایان_با
نحو:
ends_with(value: STRING, postfix: STRING) -> BOOLEAN
شرح:
اگر value با postfix خاتمه یابد، TRUE را برمیگرداند.
مثالها:
| ارزش | پسوند | ends_with(value, postfix) |
|---|---|---|
| "ای بی سی" | «سی» | درست |
| "ای بی سی" | «ب» | نادرست |
| "ای بی سی" | «» | درست |
سویفت
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();
پایتون
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() )
لایک
نحو:
like(value: STRING, pattern: STRING) -> BOOLEAN
شرح:
اگر value با pattern مطابقت داشته باشد، TRUE را برمیگرداند.
مثالها:
| ارزش | الگو | like(value, pattern) |
|---|---|---|
| «آتشنشانی» | "آتش٪" | درست |
| «آتشنشانی» | "%فروشگاه" | درست |
| «انبار داده» | "داده_ذخیره" | درست |
| «۱۰۰٪» | "۱۰۰٪" | درست |
Web
const result = await execute(db.pipeline() .collection("books") .select( field("genre").like("%Fiction") .as("anyFiction") ) );
سویفت
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();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("genre").like("%Fiction").as_("anyFiction")) .execute() )
مقادیر منظم (REGEX_CONTAINS)
نحو:
regex_contains(value: STRING, pattern: STRING) -> BOOLEAN
شرح:
اگر بخشی از value pattern مطابقت داشته باشد، TRUE برمیگرداند. اگر pattern یک عبارت منظم معتبر نباشد، این تابع error برمیگرداند.
عبارات منظم از سینتکس کتابخانه re2 پیروی میکنند.
مثالها:
| ارزش | الگو | regex_contains(value, pattern) |
|---|---|---|
| «آتشنشانی» | «آتش» | درست |
| «آتشنشانی» | "فروشگاه $" | درست |
| «آتشنشانی» | «دادهها» | نادرست |
Web
const result = await execute(db.pipeline() .collection("documents") .select( field("title").regexContains("Firestore (Enterprise|Standard)") .as("isFirestoreRelated") ) );
سویفت
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();
پایتون
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() )
تطبیق_عبارت_عبارت_مرتب
نحو:
regex_match(value: STRING, pattern: STRING) -> BOOLEAN
شرح:
اگر value کاملاً با pattern مطابقت داشته باشد، TRUE برمیگرداند. اگر pattern یک عبارت منظم معتبر نباشد، این تابع error برمیگرداند.
عبارات منظم از سینتکس کتابخانه re2 پیروی میکنند.
مثالها:
| ارزش | الگو | regex_match(value, pattern) |
|---|---|---|
| «آتشنشانی» | «فروشگاه اف.» | درست |
| «آتشنشانی» | «آتش» | نادرست |
| «آتشنشانی» | "^F.*e$" | درست |
Web
const result = await execute(db.pipeline() .collection("documents") .select( field("title").regexMatch("Firestore (Enterprise|Standard)") .as("isFirestoreExactly") ) );
سویفت
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();
پایتون
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() )
رشته_متصل
نحو:
string_concat(values: STRING...) -> STRING
شرح:
دو یا چند مقدار STRING را به یک نتیجه واحد پیوند میدهد.
مثالها:
| استدلالها | string_concat(values...) |
|---|---|
() | خطا |
("a") | «الف» |
("abc", "def") | "الف ب دف" |
("a", "", "c") | "آ سی" |
Web
const result = await execute(db.pipeline() .collection("books") .select( field("title").stringConcat(" by ", field("author")) .as("fullyQualifiedTitle") ) );
سویفت
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();
پایتون
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() )
محتویات رشته
نحو:
string_contains(value: STRING, substring: STRING) -> BOOLEAN
شرح:
بررسی میکند که آیا value شامل substring String به صورت تحتاللفظی است یا خیر.
مثالها:
| ارزش | زیررشته | string_contains(value, substring) |
|---|---|---|
| "ای بی سی" | «ب» | درست |
| "ای بی سی" | «دی» | نادرست |
| "ای بی سی" | «» | درست |
| "آ سی" | «.» | درست |
| «☃☃☃» | «☃» | درست |
Web
const result = await execute(db.pipeline() .collection("articles") .select( field("body").stringContains("Firestore") .as("isFirestoreRelated") ) );
سویفت
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();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("articles") .select(Field.of("body").string_contains("Firestore").as_("isFirestoreRelated")) .execute() )
به بالا
نحو:
to_upper[T <: STRING | BYTES](value: T) -> T
شرح:
یک مقدار STRING یا BYTES را به حروف بزرگ تبدیل میکند.
اگر یک بایت یا کاراکتر با یک کاراکتر الفبایی کوچک UTF-8 مطابقت نداشته باشد، بدون تغییر منتقل میشود.
مثالها:
| ارزش | to_upper(value) |
|---|---|
| "ای بی سی" | «ایبیسی» |
| «ایبیسی» | «ایبیسی» |
| ب"الفبا" | ب "ای بی سی" |
| ب"آ۱سی" | ب "A1C" |
Web
const result = await execute(db.pipeline() .collection("authors") .select( field("name").toUpper() .as("uppercaseName") ) );
سویفت
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();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("authors") .select(Field.of("name").to_upper().as_("uppercaseName")) .execute() )
به پایین
نحو:
to_lower[T <: STRING | BYTES](value: T) -> T
شرح:
یک مقدار STRING یا BYTES را به حروف کوچک تبدیل میکند.
اگر یک بایت یا کاراکتر با یک کاراکتر الفبایی بزرگ UTF-8 مطابقت نداشته باشد، بدون تغییر منتقل میشود.
مثالها:
| ارزش | to_lower(value) |
|---|---|
| «ایبیسی» | "ای بی سی" |
| «ایبیسی» | "ای بی سی" |
| «ای وان سی» | «ای۱سی» |
| ب "ای بی سی" | ب"الفبا" |
Web
const result = await execute(db.pipeline() .collection("authors") .select( field("genre").toLower().equal("fantasy") .as("isFantasy") ) );
سویفت
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();
پایتون
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() )
زیررشته
نحو:
substring[T <: STRING | BYTES](input: T, position: INT64) -> T
substring[T <: STRING | BYTES](input: T, position: INT64, length: INT64) -> T
شرح:
یک زیررشته از input را با شروع از position (اندیس مبتنی بر صفر) و شامل ورودیهایی با حداکثر length ، برمیگرداند. اگر length ارائه نشود، زیررشته را از position تا انتهای input برمیگرداند.
اگر
inputیک مقدارSTRINGباشد،positionوlengthبر حسب نقاط کد یونیکد اندازهگیری میشوند. اگر مقدارBYTESباشد، بر حسب بایت اندازهگیری میشوند.اگر
positionبزرگتر از طولinputباشد، یک زیررشته خالی برگردانده میشود. اگرpositionبعلاوهlengthبزرگتر از طولinputباشد، زیررشته تا انتهایinputکوتاه میشود.اگر
positionمنفی باشد، موقعیت از انتهای ورودی گرفته میشود. اگرpositionمنفی بزرگتر از اندازه ورودی باشد، موقعیت روی صفر تنظیم میشود.lengthباید غیر منفی باشد.
مثالها:
وقتی length ارائه نشده باشد:
| ورودی | موقعیت | substring(input, position) |
|---|---|---|
| "ای بی سی" | 0 | "ای بی سی" |
| "ای بی سی" | ۱ | "بی سی" |
| "ای بی سی" | ۳ | «» |
| "ای بی سی" | -1 | «سی» |
| ب"الفبا" | ۱ | بی"بی سی" |
وقتی length ارائه میشود:
| ورودی | موقعیت | طول | substring(input, position, length) |
|---|---|---|---|
| "ای بی سی" | 0 | ۱ | «الف» |
| "ای بی سی" | ۱ | ۲ | "بی سی" |
| "ای بی سی" | -1 | ۱ | «سی» |
| ب"الفبا" | 0 | ۱ | ب "الف" |
Web
const result = await execute(db.pipeline() .collection("books") .where(field("title").startsWith("The ")) .select( field("title").substring(4) .as("titleWithoutLeadingThe") ) );
سویفت
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();
پایتون
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() )
معکوس رشته
نحو:
string_reverse[T <: STRING | BYTES](input: T) -> T
شرح:
ورودی ارائه شده را به ترتیب معکوس برمیگرداند.
وقتی ورودی یک STRING باشد، کاراکترها توسط نقاط کد یونیکد و وقتی ورودی یک مقدار BYTES باشد، توسط بایتها مشخص میشوند.
مثالها:
| ورودی | string_reverse(input) |
|---|---|
| "ای بی سی" | "سی بی ای" |
| "الف🌹ب" | "بی🌹ا" |
| «سلام» | "الله" |
| ب"الفبا" | ب"سی بی ای" |
Web
const result = await execute(db.pipeline() .collection("books") .select( field("name").reverse().as("reversedName") ) );
سویفت
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();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("name").string_reverse().as_("reversedName")) .execute() )
تریم
نحو:
trim[T <: STRING | BYTES](input: T, values_to_trim: T) -> T
trim[T <: STRING | BYTES](input: T) -> T
شرح:
مجموعهای مشخص از BYTES یا CHARS را از ابتدا و انتهای input ارائه شده برش میدهد.
- اگر هیچ
values_to_trimارائه نشده باشد، کاراکترهای فاصله را حذف میکند.
مثالها:
وقتی values_to_trim ارائه نشده باشد:
| ورودی | trim(input) |
|---|---|
| "فو" | "فو" |
| ب" غذا " | ب "غذا" |
| "فو" | "فو" |
| «» | «» |
| « » | «» |
| "\t غذا \n" | "فو" |
| ب"\t غذا \n" | ب "غذا" |
| "\r\f\v غذا \r\f\v" | "فو" |
| \r\f\v غذا \r\f\v | ب "غذا" |
وقتی values_to_trim ارائه میشود:
| ورودی | مقادیر_به_تریم | trim(input, values_to_trim) |
|---|---|---|
| "abcbfooaacb" | "ای بی سی" | "فو" |
| "abcdaabadbac" | "ای بی سی" | «داآباد» |
| ب"C1C2C3" | ب"سی۱" | ب"سی۲سی۳" |
| ب"C1C2" | "فو" | خطا |
| "فو" | ب"سی۱" | خطا |
Web
const result = await execute(db.pipeline() .collection("books") .select( field("name").trim().as("whitespaceTrimmedName") ) );
سویفت
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();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("books") .select(Field.of("name").trim().as_("whitespaceTrimmedName")) .execute() )
تقسیم
نحو:
split(input: STRING) -> ARRAY<STRING>
split[T <: STRING | BYTES](input: T, delimiter: T) -> ARRAY<T>
شرح:
یک مقدار STRING یا BYTES را با استفاده از یک جداکننده تقسیم میکند.
برای
STRINGجداکننده پیشفرض کاما است,جداکننده به عنوان یک رشته واحد در نظر گرفته میشود.برای
BYTES، باید یک جداکننده مشخص کنید.تقسیم بر روی یک جداکننده خالی، آرایهای از نقاط کد یونیکد برای مقادیر
STRINGو آرایهای ازBYTESبرای مقادیرBYTESتولید میکند.تقسیم یک
STRINGخالی، یکARRAYبا یکSTRINGخالی برمیگرداند.
مثالها:
وقتی delimiter ارائه نشده باشد:
| ورودی | split(input) |
|---|---|
| «غذا، بار، غذا» | ["غذا"، "بار"، "غذا"] |
| "فو" | ["غذا"] |
| "،فو،" | ["", "غذا", ""] |
| «» | [""] |
| ب"C120C2C4" | خطا |
وقتی delimiter استفاده میشود:
| ورودی | جداکننده | split(input, delimiter) |
|---|---|---|
| "فو بار فو" | « » | ["غذا"، "بار"، "غذا"] |
| "فو بار فو" | «ز» | ["غذای بار غذا"] |
| "ای بی سی" | «» | ["الف"، "ب"، "ج"] |
| ب"C1، C2، C4" | ب"" | [ب"C1"، ب"C2"، ب"C4"] |
| ب "ای بی سی" | ب"" | [ب"الف"، ب"ب"، ب"پ"] |
| "فو" | ب"سی۱" | خطا |