aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Attard <robert.attard@mail.mcgill.ca>2021-04-08 09:59:55 -0400
committerLouis Pilfold <louis@lpil.uk>2021-04-09 10:43:35 +0100
commitb9efa53231bfd3e4929208839f6fe913f4e1f69f (patch)
tree6e69c0a353568ad6d0d07d502af5dcce021e26d6 /src
parent6324364f1b326fbd66e21134035d49de678bead7 (diff)
downloadgleam_stdlib-b9efa53231bfd3e4929208839f6fe913f4e1f69f.tar.gz
gleam_stdlib-b9efa53231bfd3e4929208839f6fe913f4e1f69f.zip
add string.drop_before #131
Diffstat (limited to 'src')
-rw-r--r--src/gleam/string.gleam14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/gleam/string.gleam b/src/gleam/string.gleam
index 7f7653c..1bec6a5 100644
--- a/src/gleam/string.gleam
+++ b/src/gleam/string.gleam
@@ -167,6 +167,20 @@ pub fn slice(from string: String, at_index idx: Int, length len: Int) -> String
}
}
+/// Drops contents of the first string that occur before the second string.
+/// If the first string does not contain the second string, the first string is returned.
+///
+/// ## Examples
+/// > drop_before(from: "The Lone Gunmen", before: "Lone")
+/// "Lone Gunmen"
+///
+pub fn drop_before(from string: String, before substring: String) -> String {
+ case split_once(string, substring) {
+ Ok(tuple(_, rest)) -> concat([substring, rest])
+ Error(Nil) -> string
+ }
+}
+
/// Drops *n* Graphemes from the left side of a string.
///
/// ## Examples