# [Ride v5] String functions
⚠️ This is the documentation for the Standard library version 5. We recommend to use version 6. Go to version 6
Name | Description | Complexity |
---|---|---|
contains(String, String): Boolean | Checks whether the string contains substring | 3 |
drop(String, Int): String | Drops the first n characters of a string | 20 |
dropRight(String, Int): String | Drops the last n characters of a string | 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 | Concatenates list strings adding a separator | 30 |
size(String): Int | Returns the size of a string | 1 |
split(String, String): List[String] | Splits a string delimited by a separator into a list of substrings | 75 |
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
Drops the first n
characters of a string.
drop(xs: String, number: Int): String
# Parameters
Parameter | Description |
---|---|
xs : String | The string |
number : Int | The number n |
# 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
# dropRight(String, Int): String
Drops the last n
characters of a string.
dropRight(xs: String, number: Int): String
# Parameters
Parameter | Description |
---|---|
xs : String | The string |
number : Int | The number n |
# 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
# 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 | The string |
substr : String | The substring |
# Examples
indexOf("Apple","ple") # Returns 2
indexOf("Apple","le") # Returns 3
indexOf("Apple","e") # Returns 4
# 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 | The string |
substr : String | The substring |
offset : Int | The index |
# Examples
indexOf("Apple","ple", 1) # Returns 2
indexOf("Apple","le", 2) # Returns 3
indexOf("Apple","e", 3) # Returns 4
indexOf("Apple","p", 0) # Returns 1
indexOf("Apple","p", 2) # Returns 2
indexOf("Apple","p", 3) # Returns unit
# 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 | The string |
substr : String | The 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 | The string |
substr : String | The substring |
offset : Int | The index |
# Examples
lastIndexOf("mamamama","ma",4) # Returns 4
lastIndexOf("mamamama","ma",3) # Returns 2
# makeString(List[String], String): String
Concatenates list strings adding a separator.
makeString(arr: List[String], separator: String): String
# 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 | The string |
# Examples
size("Ap") # Returns 2
size("Appl") # Returns 4
size("Apple") # Returns 5
# split(String, String): List[String]
Splits a string delimited by a separator into a list of substrings.
split(str: String, separator: String): List[String]
# Parameters
Parameter | Description |
---|---|
str : String | The string |
separator : Int | The 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 | The string |
number : Int | The number n |
# 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) # Returns an empty string
# takeRight(String, Int): String
Takes the last n
characters from a string.
takeRight(xs: String, number: Int): String
# Parameters
Parameter | Description |
---|---|
xs : String | The string |
number : Int | The number n |
# 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"