string_editor
Values
pub fn after(
string: String,
on pattern: String,
) -> Result(String, Nil)
Returns the part of a string after the first occurrence of a given substring.
If the substring is not found, it returns Error(Nil)
.
Examples
after(“hello world”, on: “ “) Ok(“world”)
after(“gleam is fun”, on: “!”) Error(Nil)
pub fn after_all(
string: String,
on pattern: String,
) -> List(String)
Returns all parts of a string after each occurrence of a given substring.
Examples
after_all(“a.b.c.d”, on: “.”) [“b.c.d”, “c.d”, “d”]
after_all(“hello world”, on: “!”) []
pub fn after_at(
string: String,
on pattern: String,
at index: Int,
) -> Result(String, Nil)
Returns the part of a string after the nth occurrence of a given substring.
Index is 0-based. If the pattern doesn’t occur enough times, returns Error(Nil)
.
Examples
after_at(“a.b.c.d”, on: “.”, at: 1) Ok(“c.d”)
after_at(“hello world”, on: “ “, at: 5) Error(Nil)
pub fn before(
string: String,
on pattern: String,
) -> Result(String, Nil)
Returns the part of a string before the first occurrence of a given substring.
If the substring is not found, it returns Error(Nil)
.
Examples
before(“hello world”, on: “ “) Ok(“hello”)
before(“gleam is fun”, on: “!”) Error(Nil)
pub fn before_all(
string: String,
on pattern: String,
) -> List(String)
Returns all parts of a string before each occurrence of a given substring.
Examples
before_all(“a.b.c.d”, on: “.”) [“a”, “a.b”, “a.b.c”]
before_all(“hello world”, on: “!”) []
pub fn before_at(
string: String,
on pattern: String,
at index: Int,
) -> Result(String, Nil)
Returns the part of a string before the nth occurrence of a given substring.
Index is 0-based. If the pattern doesn’t occur enough times, returns Error(Nil)
.
Examples
before_at(“a.b.c.d”, on: “.”, at: 1) Ok(“a.b”)
before_at(“hello world”, on: “ “, at: 5) Error(Nil)
pub fn between(
string: String,
from start: String,
to end: String,
) -> Result(String, Nil)
Returns the part of a string between two given substrings.
It finds the first occurrence of start
and then the first
occurrence of end
after start
. If either is not found in the
correct order, it returns Error(Nil)
.
Examples
between(“
title
”, from: “”, to: “”) Error(Nil)
pub fn between_all(
string: String,
from start: String,
to end: String,
) -> List(String)
pub fn between_at(
string: String,
from start: String,
to end: String,
at index: Int,
) -> Result(String, Nil)
Returns the part of a string between the nth occurrence of start and the first occurrence of end after that.
Index is 0-based for the start pattern. If patterns don’t occur enough times, returns Error(Nil)
.
Examples
between_at(“
title
”, from: “”, to: “”, at: 0) Error(Nil)