From e7404b06e464b97670a106b3aed916e211687609 Mon Sep 17 00:00:00 2001 From: Daniel Sainati Date: Fri, 22 Dec 2023 12:28:17 -0500 Subject: [PATCH] add documentation for new string functions --- .../version-1.0/language/values-and-types.mdx | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/versioned_docs/version-1.0/language/values-and-types.mdx b/versioned_docs/version-1.0/language/values-and-types.mdx index 5c0f8c2..1ada020 100644 --- a/versioned_docs/version-1.0/language/values-and-types.mdx +++ b/versioned_docs/version-1.0/language/values-and-types.mdx @@ -889,6 +889,34 @@ Strings have multiple built-in functions you can use: example.toLower() // is `flowers` ``` +- + ```cadence + view fun replaceAll(of: String, with: String): String + ``` + + Returns a string where all occurences of `of` are replaced with `with`. + If `of` is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding k+1 replacements for a string of length k. + + ```cadence + let example = "abababa" + + example.replaceAll(of: "a", with: "o") // is `obobobo` + ``` + +- + ```cadence + view fun split(separator: String): [String] + ``` + + Returns the variable-sized array of strings created splitting the receiver string on the `separator`. + + ```cadence + let example = "hello world" + + example.split(separator: " ") // is `["hello", "world"]` + ``` + + The `String` type also provides the following functions: - @@ -904,6 +932,18 @@ The `String` type also provides the following functions: String.encodeHex(data) // is `"010203cade"` ``` +- + ```cadence + view fun String.join(_ strings: [String], separator: String): String + ``` + + Returns the string created by joining the array of `strings` with the provided `separator`. + + ```cadence + let strings = ["hello", "world"] + String.join(strings, " ") // is "hello world" + ``` + `String`s are also indexable, returning a `Character` value. ```cadence