# [Ride v6] String functions
⚠️ This is the documentation for the Standard Library version 6, which becomes available after activation of feature #17 “Ride V6, MetaMask support”. Go to version 5
Name | Description | Complexity |
---|---|---|
contains(String, String): Boolean | Checks whether the string contains substring | 3 |
drop(String, Int): String | Returns a given string without the first N characters | 20 |
dropRight(String, Int): String | Returns a given string without the last N characters | 20 |
indexOf(String, String): Int|Unit | Returns the index of the first occurrence of a substring | 3 |
indexOf(String, String, Int): Int|Unit | Returns the index of the first occurrence of a substring after a certain index | 3 |
lastIndexOf(String, String): Int|Unit | Returns the index of the last occurrence of a substring | 3 |
lastindexOf(String, String, Int): Int|Unit | Returns the index of the last occurrence of a substring before a certain index | 3 |
makeString(List[String], String): String | Range of functions. Concatenate list strings adding a separator | 1–11 |
size(String): Int | Returns the size of a string | 1 |
split(String, String): List[String] | Range of functions. Split a string delimited by a separator into a list of substrings | 1–51 |
take(String, Int): String | Takes the first N characters from a string | 20 |
takeRight(String, Int): String | Takes the last N characters from a string | 20 |
# contains(String, String): Boolean
Checks whether the string contains substring.
contains(haystack: String, needle: String): Boolean
# Parameters
Parameter | Description |
---|---|
haystack : String | String to search in |
needle : String | String to search for |
# Examples
"hello".contains("hell") # Returns true
"hello".contains("world") # Returns false
# drop(String, Int): String
Returns a given string without the first N
characters.
drop(xs: String, number: Int): String
# Parameters
Parameter | Description |
---|---|
xs : String | String |
number : Int | Number N . From 0 to 32,767 |
# Examples
drop("Apple", 0) # Returns "Apple"
drop("Apple", 1) # Returns "pple"
drop("Apple", 3) # Returns "le"
drop("Apple", 5) # Returns an empty string
drop("Apple", 15) # Returns an empty string
drop("Apple", -10) # Fails
# dropRight(String, Int): String
Returns a given string without the last N
characters of a string.
dropRight(xs: String, number: Int): String
# Parameters
Parameter | Description |
---|---|
xs : String | String |
number : Int | Number N . From 0 to 32,767 |
# Examples
dropRight("Apple", 0) # Returns "Apple"
dropRight("Apple", 1) # Returns "Appl"
dropRight("Apple", 3) # Returns "Ap"
dropRight("Apple", 5) # Returns an empty string
dropRight("Apple", 15) # Returns an empty string
dropRight("Apple", -1) # Fails
# indexOf(String, String): Int|Unit
Returns the index of the first occurrence of a substring.
indexOf(str: String, substr: String): Int|Unit
# Parameters
Parameter | Description |
---|---|
str : String | String |
substr : String | Substring |
# Examples
indexOf("Apple","ple") # Returns 3
indexOf("Apple","le") # Returns 4
indexOf("Apple","e") # Returns 5
# indexOf(String, String, Int): Int|Unit
Returns the index of the first occurrence of a substring after a certain index.
indexOf(str: String, substr: String, offset: Int): Int|Unit
# Parameters
Parameter | Description |
---|---|
str : String | String |
substr : String | Substring |
offset : Int | Index |
# Examples
indexOf("Apple","ple", 1) # Returns 2
indexOf("Apple","le", 2) # Returns 3
indexOf("Apple","e", 3) # Returns 4
# lastIndexOf(String, String): Int|Unit
Returns the index of the last occurrence of a substring.
lastIndexOf(str: String, substr: String): Int|Unit
# Parameters
Parameter | Description |
---|---|
str : String | String |
substr : String | Substring |
# Examples
lastIndexOf("Apple","pp") # Returns 1
lastIndexOf("Apple","p") # Returns 2
lastIndexOf("Apple","s") # Returns unit
# lastIndexOf(String, String, Int): Int|Unit
Returns the index of the last occurrence of a substring before a certain index.
lastIndexOf(str: String, substr: String, offset: Int): Int|Unit
# Parameters
Parameter | Description |
---|---|
str : String | String |
substr : String | Substring |
offset : Int | Index |
# Examples
lastIndexOf("mamamama","ma",4) # Returns 4
lastIndexOf("mamamama","ma",3) # Returns 2
# makeString(List[String], String): String
Range of functions. Concatenate list strings adding a separator.
makeString(arr: List[String], separator: String): String
makeString_2С(arr: List[String], separator: String): String
makeString_11С(arr: List[String], separator: String): String
Name | Limitations | Complexity |
---|---|---|
makeString | Input list up to 70 elements; result up to 500 bytes | 1 |
makeString_2С | Input list up to 100 elements; result up to 6000 bytes | 2 |
makeString_11C | — | 11 |
# Parameters
Parameter | Description |
---|---|
arr : List[String] | List of strings to concatenate |
separator : String | Separator |
# Example
makeString(["Apple","Orange","Mango"], " & ") # Returns "Apple & Orange & Mango"
# size(String): Int
Returns the size of a string.
size(xs: String): Int
# Parameters
Parameter | Description |
---|---|
xs : String | String |
# Examples
size("Ap") # Returns 2
size("Appl") # Returns 4
size("Apple") # Returns 5
# split(String, String): List[String]
Range of functions. Split a string delimited by a separator into a list of substrings.
split(str: String, separator: String): List[String]
split_4С(str: String, separator: String): List[String]
split_51C(str: String, separator: String): List[String]
Name | Limitations | Complexity |
---|---|---|
split | Input string up to 500 bytes; result up to 20 elements | 1 |
split_4С | Input string up to 6000 bytes; result up to 100 elements | 4 |
split_51C | — | 51 |
# Parameters
Parameter | Description |
---|---|
str : String | String |
separator : Int | Separator |
# Examples
split("A.p.p.l.e", ".") # Returns ["A", "p", "p", "l", "e"]
split("Apple", ".") # Returns ["Apple"]
split("Apple", "") # Returns ["A", "p", "p", "l", "e"]
split("Ap.ple", ".") # Returns ["Ap","ple"]
# take(String, Int): String
Takes the first N
characters from a string.
take(xs: String, number: Int): String
# Parameters
Parameter | Description |
---|---|
xs : String | String |
number : Int | Number N . From 0 to 32,767 |
# Examples
take("Apple", 0) # Returns an empty string
take("Apple", 1) # Returns "A"
take("Apple", 3) # Returns "App"
take("Apple", 5) # Returns "Apple"
take("Apple", 15) # Returns "Apple"
take("Apple", -10) # Fails
# takeRight(String, Int): String
Takes the last n
characters from a string.
takeRight(xs: String, number: Int): String
# Parameters
Parameter | Description |
---|---|
xs : String | String |
number : Int | Number N . From 0 to 32,767 |
# Examples
takeRight("Apple", 0) # Returns an empty string
takeRight("Apple", 1) # Returns "e"
takeRight("Apple", 3) # Returns "ple"
takeRight("Apple", 5) # Returns "Apple"
takeRight("Apple", 15) # Returns "Apple"
takeRight("Apple", -10) # Fails