String functions
# | Name | Description | Complexity |
---|---|---|---|
1 | drop(String, Int): String | Drops the first n characters of a string |
1 |
2 | dropRight(String, Int): String | Drops the last n characters of a string |
19 |
3 | indexOf(String, String): Int|Unit | Returns the index of the first occurrence of a substring | 20 |
4 | indexOf(String, String, Int): Int|Unit | Returns the index of the first occurrence of a substring after a certain index | 20 |
5 | size(String): Int | Returns the size of a string | 1 |
6 | split(String, String): List[String] | Splits a string delimited by a separator into a list of substrings | 100 |
7 | take(String, Int): String | Takes the first n characters from a string |
1 |
8 | takeRight(String, Int): String | Takes the last n characters from a string |
19 |
drop(String, Int): Str
Drops the first n
characters of a string.
drop(xs: String, number: Int): String
Parameters
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
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
str
: String
The string.
substr
: String
The 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
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
size(String): Int
Returns the size of a string.
size(xs: String): Int
Parameters
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
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
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
xs
: String
The string.
number
: Int
The number n
.
Examples
takeRight("Apple", 0) # Returns an empty string
takeRight("Apple", 1) # Returns "A"
takeRight("Apple", 3) # Returns "ple"
takeRight("Apple", 5) # Returns "Apple"
takeRight("Apple", 15) # Returns "Apple"