توابع رشتهای
| نام | توضیحات |
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 برمیگرداند. |
STRING_INDEX_OF | ایندکس مبتنی بر 0 اولین وقوع یک مقدار STRING یا BYTES را برمیگرداند. |
TO_UPPER | یک مقدار STRING یا BYTES را به حروف بزرگ تبدیل میکند. |
TO_LOWER | یک مقدار STRING یا BYTES را به حروف کوچک تبدیل میکند. |
SUBSTRING | یک زیررشته از یک مقدار STRING یا BYTES دریافت میکند. |
STRING_REVERSE | مقدار STRING یا BYTES را معکوس میکند. |
STRING_REPEAT | یک مقدار STRING یا BYTES را به تعداد دفعات مشخص تکرار میکند. |
STRING_REPLACE_ALL | تمام موارد وقوع یک مقدار STRING یا BYTES را جایگزین میکند. |
STRING_REPLACE_ONE | اولین مورد از یک مقدار STRING یا BYTES را جایگزین میکند. |
TRIM | کاراکترهای اول و آخر یک مقدار STRING یا BYTES را حذف میکند. |
LTRIM | کاراکترهای ابتدای یک مقدار STRING یا BYTES را حذف میکند. |
RTRIM | کاراکترهای انتهایی یک مقدار STRING یا BYTES را حذف میکند. |
SPLIT | یک مقدار STRING یا BYTES را به یک آرایه تقسیم میکند. |
طول بایت
نحو:
byte_length[T <: STRING | BYTES](value: T) -> INT64
شرح:
تعداد BYTES در یک مقدار STRING یا BYTES را برمیگرداند.
مثالها:
| ارزش | byte_length(value) |
|---|---|
| "ای بی سی" | ۳ |
| "xyzabc" | ۶ |
| ب"الفبا" | ۳ |
نود جی اس
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") ) );
سویفت
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() )
جاوا
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(byteLength(field("title")).as("titleByteLength")) .execute() .get();
طول کاراکتر
نحو:
char_length(value: STRING) -> INT64
شرح:
تعداد نقاط کد یونیکد را در مقدار STRING برمیگرداند.
مثالها:
| ارزش | char_length(value) |
|---|---|
| "ای بی سی" | ۳ |
| «سلام» | ۵ |
| «جهان» | ۵ |
نود جی اس
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") ) );
سویفت
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() )
جاوا
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(charLength(field("title")).as("titleCharLength")) .execute() .get();
شروع_با
نحو:
starts_with(value: STRING, prefix: STRING) -> BOOLEAN
شرح:
اگر value با prefix شروع شود، TRUE برمیگرداند.
مثالها:
| ارزش | پیشوند | starts_with(value, prefix) |
|---|---|---|
| "ای بی سی" | «الف» | درست |
| "ای بی سی" | «ب» | نادرست |
| "ای بی سی" | «» | درست |
نود جی اس
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") ) );
سویفت
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() )
جاوا
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(startsWith(field("title"), "The").as("needsSpecialAlphabeticalSort")) .execute() .get();
پایان_با
نحو:
ends_with(value: STRING, postfix: STRING) -> BOOLEAN
شرح:
اگر value با postfix خاتمه یابد، TRUE را برمیگرداند.
مثالها:
| ارزش | پسوند | ends_with(value, postfix) |
|---|---|---|
| "ای بی سی" | «سی» | درست |
| "ای بی سی" | «ب» | نادرست |
| "ای بی سی" | «» | درست |
نود جی اس
const result = await db.pipeline() .collection("inventory/devices/laptops") .select( field("name").endsWith("16 inch") .as("16InLaptops") ) .execute();
سویفت
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() )
جاوا
Pipeline.Snapshot result = firestore .pipeline() .collection("inventory/devices/laptops") .select(endsWith(field("name"), "16 inch").as("16InLaptops")) .execute() .get();
لایک
نحو:
like(value: STRING, pattern: STRING) -> BOOLEAN
شرح:
اگر value با pattern مطابقت داشته باشد، TRUE را برمیگرداند.
مثالها:
| ارزش | الگو | like(value, pattern) |
|---|---|---|
| «آتشنشانی» | "آتش٪" | درست |
| «آتشنشانی» | "%فروشگاه" | درست |
| «انبار داده» | "داده_ذخیره" | درست |
| «۱۰۰٪» | "۱۰۰٪" | درست |
نود جی اس
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") ) );
سویفت
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() )
جاوا
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(like(field("genre"), "%Fiction").as("anyFiction")) .execute() .get();
مقادیر منظم (REGEX_CONTAINS)
نحو:
regex_contains(value: STRING, pattern: STRING) -> BOOLEAN
شرح:
اگر بخشی از value pattern مطابقت داشته باشد، TRUE برمیگرداند. اگر pattern یک عبارت منظم معتبر نباشد، این تابع error برمیگرداند.
عبارات منظم از سینتکس کتابخانه re2 پیروی میکنند.
مثالها:
| ارزش | الگو | regex_contains(value, pattern) |
|---|---|---|
| «آتشنشانی» | «آتش» | درست |
| «آتشنشانی» | "فروشگاه $" | درست |
| «آتشنشانی» | «دادهها» | نادرست |
نود جی اس
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") ) );
سویفت
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() )
جاوا
Pipeline.Snapshot result = firestore .pipeline() .collection("documents") .select( regexContains(field("title"), "Firestore (Enterprise|Standard)") .as("isFirestoreRelated")) .execute() .get();
تطبیق_عبارت_عبارت_مرتب
نحو:
regex_match(value: STRING, pattern: STRING) -> BOOLEAN
شرح:
اگر value کاملاً با pattern مطابقت داشته باشد، TRUE برمیگرداند. اگر pattern یک عبارت منظم معتبر نباشد، این تابع error برمیگرداند.
عبارات منظم از سینتکس کتابخانه re2 پیروی میکنند.
مثالها:
| ارزش | الگو | regex_match(value, pattern) |
|---|---|---|
| «آتشنشانی» | «فروشگاه اف.» | درست |
| «آتشنشانی» | «آتش» | نادرست |
| «آتشنشانی» | "^F.*e$" | درست |
نود جی اس
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") ) );
سویفت
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() )
جاوا
Pipeline.Snapshot result = firestore .pipeline() .collection("documents") .select( regexMatch(field("title"), "Firestore (Enterprise|Standard)") .as("isFirestoreExactly")) .execute() .get();
رشته_متصل
نحو:
string_concat(values: STRING...) -> STRING
شرح:
دو یا چند مقدار STRING را به یک نتیجه واحد پیوند میدهد.
مثالها:
| استدلالها | string_concat(values...) |
|---|---|
() | خطا |
("a") | «الف» |
("abc", "def") | "الف ب دف" |
("a", "", "c") | "آ سی" |
نود جی اس
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") ) );
سویفت
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() )
جاوا
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(stringConcat(field("title"), " by ", field("author")).as("fullyQualifiedTitle")) .execute() .get();
محتویات رشته
نحو:
string_contains(value: STRING, substring: STRING) -> BOOLEAN
شرح:
بررسی میکند که آیا value شامل substring String به صورت تحتاللفظی است یا خیر.
مثالها:
| ارزش | زیررشته | string_contains(value, substring) |
|---|---|---|
| "ای بی سی" | «ب» | درست |
| "ای بی سی" | «دی» | نادرست |
| "ای بی سی" | «» | درست |
| "آ سی" | «.» | درست |
| «☃☃☃» | «☃» | درست |
نود جی اس
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") ) );
سویفت
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() )
جاوا
Pipeline.Snapshot result = firestore .pipeline() .collection("articles") .select(stringContains(field("body"), "Firestore").as("isFirestoreRelated")) .execute() .get();
STRING_INDEX_OF
نحو:
string_index_of[T <: STRING | BYTES](value: T, search: T) -> INT64
شرح:
ایندکس مبتنی بر ۰ اولین رخداد search در value را برمیگرداند.
- اگر
searchپیدا نشود،-1را برمیگرداند. - اگر
valueیک مقدارSTRINGباشد، نتیجه بر حسب امتیاز کد یونیکد اندازهگیری میشود. اگر مقدار یک مقدارBYTESباشد، بر حسب بایت اندازهگیری میشود. - اگر
searchیک مقدارSTRINGیاBYTESخالی باشد، نتیجه0است.
مثالها:
| ارزش | جستجو | string_index_of(value, search) |
|---|---|---|
| "سلام دنیا" | «ای» | ۴ |
| "سلام دنیا" | «ل» | ۲ |
| "سلام دنیا" | «ز» | -1 |
| «موز» | «نا» | ۲ |
| "ای بی سی" | «» | 0 |
| ب"الفبا" | ب "ب" | ۱ |
| "ه" | "ه" | 0 |
| ب "é" | ب "é" | 0 |
به بالا
نحو:
to_upper[T <: STRING | BYTES](value: T) -> T
شرح:
یک مقدار STRING یا BYTES را به حروف بزرگ تبدیل میکند.
اگر یک بایت یا کاراکتر با یک کاراکتر الفبایی کوچک UTF-8 مطابقت نداشته باشد، بدون تغییر منتقل میشود.
مثالها:
| ارزش | to_upper(value) |
|---|---|
| "ای بی سی" | «ایبیسی» |
| «ایبیسی» | «ایبیسی» |
| ب"الفبا" | ب "ای بی سی" |
| ب"آ۱سی" | ب "A1C" |
نود جی اس
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") ) );
سویفت
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() )
جاوا
Pipeline.Snapshot result = firestore .pipeline() .collection("authors") .select(toUpper(field("name")).as("uppercaseName")) .execute() .get();
به پایین
نحو:
to_lower[T <: STRING | BYTES](value: T) -> T
شرح:
یک مقدار STRING یا BYTES را به حروف کوچک تبدیل میکند.
اگر یک بایت یا کاراکتر با یک کاراکتر الفبایی بزرگ UTF-8 مطابقت نداشته باشد، بدون تغییر منتقل میشود.
مثالها:
| ارزش | to_lower(value) |
|---|---|
| «ایبیسی» | "ای بی سی" |
| «ایبیسی» | "ای بی سی" |
| «ای وان سی» | «ای۱سی» |
| ب "ای بی سی" | ب"الفبا" |
نود جی اس
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") ) );
سویفت
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() )
جاوا
Pipeline.Snapshot result = firestore .pipeline() .collection("authors") .select(equal(toLower(field("genre")), "fantasy").as("isFantasy")) .execute() .get();
زیررشته
نحو:
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 | ۱ | ب "الف" |
نود جی اس
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") ) );
سویفت
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() )
جاوا
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[T <: STRING | BYTES](input: T) -> T
شرح:
ورودی ارائه شده را به ترتیب معکوس برمیگرداند.
وقتی ورودی یک STRING باشد، کاراکترها توسط نقاط کد یونیکد و وقتی ورودی یک مقدار BYTES باشد، توسط بایتها مشخص میشوند.
مثالها:
| ورودی | string_reverse(input) |
|---|---|
| "ای بی سی" | "سی بی ای" |
| "الف🌹ب" | "بی🌹ا" |
| «سلام» | "الله" |
| ب"الفبا" | ب"سی بی ای" |
نود جی اس
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") ) );
سویفت
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() )
جاوا
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(reverse(field("name")).as("reversedName")) .execute() .get();
تکرار رشته
نحو:
string_repeat[T <: STRING | BYTES](input: T, repetitions: INT64) -> T
شرح:
تعداد repetitions input را برمیگرداند.
-
repetitionsباید یک عدد صحیح غیر منفی باشند. - اگر
repetitions0باشد، یک مقدار خالی از همان نوعinputرا برمیگرداند. - اگر نتیجه از حداکثر اندازه مجاز (۱ مگابایت) بیشتر شود، خطایی برگردانده میشود.
مثالها:
| ورودی | تکرارها | string_repeat(input, repetitions) |
|---|---|---|
| "فو" | ۳ | "فوفوفو" |
| "فو" | 0 | «» |
| «الف» | ۳ | «آآ» |
| ب"آب" | ۲ | ب"باب" |
| "ه🦆" | ۲ | "این🦆این🦆" |
STRING_REPLACE_ALL
نحو:
string_replace_all[T <: STRING | BYTES](input: T, find: T, replacement: T) -> T
شرح:
تمام رخدادهای غیرهمپوشانی find در input را با replacement جایگزین میکند.
- تطابقها به حروف کوچک و بزرگ حساس هستند.
- اگر
findخالی باشد، هیچ جایگزینی انجام نمیشود.
مثالها:
| ورودی | پیدا کردن | جایگزینی | string_replace_all(input, find, replacement) |
|---|---|---|---|
| "فوبارفو" | "فو" | «باز» | «بازبارباز» |
| «باباب» | «آبا» | «سی» | "کباب" |
| "فوبار" | «ای» | «» | "فبار" |
| "ه🦆🌎🦆" | «🦆» | «الف» | "اِا🌎ا" |
| ب"الفبا" | ب "ب" | ب"د" | ب"adc" |
یک رشته را جایگزین کنید
نحو:
string_replace_one[T <: STRING | BYTES](input: T, find: T, replacement: T) -> T
شرح:
اولین مورد از find در input را با replacement جایگزین میکند.
- تطابقها به حروف کوچک و بزرگ حساس هستند.
- اگر
findخالی باشد، هیچ جایگزینی انجام نمیشود.
مثالها:
| ورودی | پیدا کردن | جایگزینی | string_replace_one(input, find, replacement) |
|---|---|---|---|
| "فوبارفو" | "فو" | «باز» | "بازبرفو" |
| "ه" | "ه" | «الف» | «الف» |
| ب"فوبار" | ب "او" | ب"ز" | ب"فزوبار" |
تریم
نحو:
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() )
جاوا
Pipeline.Snapshot result = firestore .pipeline() .collection("books") .select(trim(field("name")).as("whitespaceTrimmedName")) .execute() .get();
لتریم
نحو:
ltrim[T <: STRING | BYTES](value: T, to_trim: T) -> T
ltrim[T <: STRING | BYTES](value: T) -> T
شرح:
مجموعه مشخصی از BYTES یا CHARS را از ابتدای value ارائه شده برش میدهد.
- اگر
to_trimارائه نشده باشد، کاراکترهای فاصلهی ابتدای تابع را حذف میکند.
مثالها:
چه زمانی to_trim ارائه نمیشود:
| ارزش | ltrim(value) |
|---|---|
| "فو" | "فو" |
| "فو" | "فو" |
چه زمانی to_trim ارائه میشود:
| ارزش | to_trim | ltrim(value, to_trim) |
|---|---|---|
| "آاِی بی سی" | «الف» | "بی سی" |
| «آباکابا» | "با" | "کابا" |
| "ه" | "ه" | «» |
آرتریم
نحو:
rtrim[T <: STRING | BYTES](value: T, to_trim: T) -> T
rtrim[T <: STRING | BYTES](value: T) -> T
شرح:
مجموعه مشخصی از BYTES یا CHARS را از انتهای value ارائه شده برش میدهد.
- اگر
to_trimارائه نشده باشد، کاراکترهای فاصلهی انتهایی را حذف میکند.
مثالها:
چه زمانی to_trim ارائه نمیشود:
| ارزش | rtrim(value) |
|---|---|
| "فو" | "فو" |
| "فو" | "فو" |
چه زمانی to_trim ارائه میشود:
| ارزش | to_trim | rtrim(value, to_trim) |
|---|---|---|
| "ای بی سی سی" | «سی» | "آب" |
| «آباکابا» | "با" | "آباک" |
| "ه" | "ه" | «» |
تقسیم
نحو:
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"] |
| ب "ای بی سی" | ب"" | [ب"الف"، ب"ب"، ب"پ"] |
| "فو" | ب"سی۱" | خطا |