문자열 함수

문자열 함수

이름 설명
BYTE_LENGTH STRING 또는 BYTES 값에 있는 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

구문:

byte_length[T <: STRING | BYTES](value: T) -> INT64

설명:

STRING 또는 BYTES 값에 있는 BYTES의 수를 반환합니다.

예:

byte_length(value)
"abc" 3
"xyzabc" 6
b"abc" 3

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()
)

CHAR_LENGTH

구문:

char_length(value: STRING) -> INT64

설명:

STRING 값의 유니코드 코드 포인트 수를 반환합니다.

예:

char_length(value)
"abc" 3
"hello" 5
"world" 5

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()
)

STARTS_WITH

구문:

starts_with(value: STRING, prefix: STRING) -> BOOLEAN

설명:

valueprefix로 시작하면 TRUE를 반환합니다.

예:

접두사 starts_with(value, prefix)
"abc" "a"
"abc" "b" 거짓
"abc" ""

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()
)

ENDS_WITH

구문:

ends_with(value: STRING, postfix: STRING) -> BOOLEAN

설명:

valuepostfix로 끝나면 TRUE를 반환합니다.

예:

postfix ends_with(value, postfix)
"abc" "c"
"abc" "b" 거짓
"abc" ""
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()
)

LIKE

구문:

like(value: STRING, pattern: STRING) -> BOOLEAN

설명:

valuepattern과 일치하면 TRUE를 반환합니다.

예:

패턴 like(value, pattern)
"Firestore" "Fire%"
"Firestore" "%store"
"Datastore" "Data_tore"
"100%" "100\%"

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()
)

REGEX_CONTAINS

구문:

regex_contains(value: STRING, pattern: STRING) -> BOOLEAN

설명:

value의 일부가 pattern과 일치하면 TRUE를 반환합니다. pattern이 유효한 정규 표현식이 아니면 이 함수는 error를 반환합니다.

정규 표현식은 re2 라이브러리의 구문을 따릅니다.

예:

패턴 regex_contains(value, pattern)
"Firestore" "Fire"
"Firestore" "store$"
"Firestore" "data" 거짓

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()
)

REGEX_MATCH

구문:

regex_match(value: STRING, pattern: STRING) -> BOOLEAN

설명:

valuepattern과 완전히 일치하면 TRUE를 반환합니다. pattern이 유효한 정규 표현식이 아니면 이 함수는 error를 반환합니다.

정규 표현식은 re2 라이브러리의 구문을 따릅니다.

예:

패턴 regex_match(value, pattern)
"Firestore" "F.*store"
"Firestore" "Fire" 거짓
"Firestore" "^F.*e$"

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()
)

STRING_CONCAT

구문:

string_concat(values: STRING...) -> STRING

설명:

둘 이상의 STRING 값을 하나의 결과로 연결합니다.

예:

인수 string_concat(values...)
() 오류
("a") "a"
("abc", "def") "abcdef"
("a", "", "c") "ac"

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()
)

STRING_CONTAINS

구문:

string_contains(value: STRING, substring: STRING) -> BOOLEAN

설명:

value에 리터럴 문자열 substring이 포함되어 있는지 확인합니다.

예:

substring string_contains(value, substring)
"abc" "b"
"abc" "d" 거짓
"abc" ""
"a.c" "."
"☃☃☃" "☃"

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()
)

TO_UPPER

구문:

to_upper[T <: STRING | BYTES](value: T) -> T

설명:

STRING 또는 BYTES 값을 대문자로 변환합니다.

바이트 또는 문자가 UTF-8 소문자 알파벳 문자에 해당하지 않으면 변경되지 않고 전달됩니다.

예:

to_upper(value)
"abc" "ABC"
"AbC" "ABC"
b"abc" b"ABC"
b"a1c" b"A1C"

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()
)

TO_LOWER

구문:

to_lower[T <: STRING | BYTES](value: T) -> T

설명:

STRING 또는 BYTES 값을 소문자로 변환합니다.

바이트 또는 문자가 UTF-8 대문자 알파벳 문자에 해당하지 않으면 변경되지 않고 전달됩니다.

예:

to_lower(value)
"ABC" "abc"
"AbC" "abc"
"A1C" "a1c"
b"ABC" b"abc"

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()
)

SUBSTRING

구문:

substring[T <: STRING | BYTES](input: T, position: INT64) -> T
substring[T <: STRING | BYTES](input: T, position: INT64, length: INT64) -> T

설명:

position(0부터 시작하는 색인)에서 시작하여 최대 length 항목을 포함하는 input의 하위 문자열을 반환합니다. length가 제공되지 않으면 position부터 input 끝까지의 하위 문자열을 반환합니다.

  • inputSTRING 값인 경우 positionlength는 유니코드 코드 포인트로 측정됩니다. BYTES 값인 경우 바이트로 측정됩니다.

  • positioninput의 길이보다 크면 빈 하위 문자열이 반환됩니다. position 더하기 lengthinput의 길이보다 크면 하위 문자열이 input의 끝으로 잘립니다.

  • position이 음수이면 입력의 끝에서 위치를 가져옵니다. 음수 position이 입력 크기보다 크면 위치가 0으로 설정됩니다. length는 음수가 아니어야 합니다.

예:

length가 제공되지 않는 경우:

입력 위치 substring(input, position)
"abc" 0 "abc"
"abc" 1 "bc"
"abc" 3 ""
"abc" -1 "c"
b"abc" 1 b"bc"

length가 제공되는 경우:

입력 위치 길이 substring(input, position, length)
"abc" 0 1 "a"
"abc" 1 2 "bc"
"abc" -1 1 "c"
b"abc" 0 1 b"a"

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()
)

STRING_REVERSE

구문:

string_reverse[T <: STRING | BYTES](input: T) -> T

설명:

제공된 입력을 역순으로 반환합니다.

입력이 STRING인 경우 문자는 유니코드 코드 포인트로 구분되고, 입력이 BYTES 값인 경우 바이트로 구분됩니다.

예:

입력 string_reverse(input)
"abc" "cba"
"a🌹b" "b🌹a"
"hello" "olleh"
b"abc" b"cba"

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()
)

TRIM

구문:

trim[T <: STRING | BYTES](input: T, values_to_trim: T) -> T
trim[T <: STRING | BYTES](input: T) -> T

설명:

제공된 input의 시작과 끝에서 지정된 BYTES 또는 CHARS 집합을 자릅니다.

  • values_to_trim이 제공되지 않으면 공백 문자를 자릅니다.

예:

values_to_trim가 제공되지 않는 경우:

입력 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"

values_to_trim이 제공되는 경우:

입력 values_to_trim trim(input, values_to_trim)
"abcbfooaacb" "abc" 'foo'
"abcdaabadbac" "abc" "daabad"
b"C1C2C3" b"C1" b"C2C3"
b"C1C2" 'foo' 오류
'foo' b"C1" 오류

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()
)

SPLIT

구문:

split(input: STRING) -> ARRAY<STRING>
split[T <: STRING | BYTES](input: T, delimiter: T) -> ARRAY<T>

설명:

구분자를 사용하여 STRING 또는 BYTES 값을 분할합니다.

  • STRING에서 기본 구분자는 쉼표(,)입니다. 구분자는 단일 문자열로 처리됩니다.

  • BYTES에서는 구분 기호를 지정해야 합니다.

  • 비어 있는 구분자로 분할하면 STRING 값의 경우에는 유니코드 코드 포인트 배열이, BYTES 값의 경우에는 BYTES의 배열이 생성됩니다.

  • 비어 있는 STRING을 분할하면 비어 있는 STRING이 하나 있는 ARRAY가 반환됩니다.

예:

delimiter가 제공되지 않는 경우:

입력 split(input)
"foo,bar,foo" ["foo", "bar", "foo"]
'foo' ["foo"]
",foo," ["", "foo", ""]
"" [""]
b"C120C2C4" 오류

delimiter가 제공되는 경우:

입력 구분자 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" 오류