From b9efa53231bfd3e4929208839f6fe913f4e1f69f Mon Sep 17 00:00:00 2001 From: Robert Attard Date: Thu, 8 Apr 2021 09:59:55 -0400 Subject: add string.drop_before #131 --- src/gleam/string.gleam | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src') 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 -- cgit v1.2.3