Function in text coil-stdlib

split_at

fn split_at(string s, int at) -> Result<(string, string), string>
Import
use text::{split_at};
Source: src/text.hy

Splits s at byte offset at into the part before and the part from at on.

Parameters#

NameType
sstring
atint

Returns#

Result<(string, string), string>

Errors#

Returns Err("utf8") when at falls inside a multi-byte character.

Examples#

use text::{split_at};
use tests::assert;
let (a, b) = split_at("hello", 2) ?? ("", "");
assert!(a == "he" && b == "llo");

See also#

  • byte_len: Returns the length of s in bytes; the same as s.len().
  • slice: Returns the part of s from byte offset start up to (not including) end.
  • trim_start: Returns s without leading ASCII whitespace (space, tab, CR, LF).
  • trim_end: Returns s without trailing ASCII whitespace (space, tab, CR, LF).
  • trim: Returns s without leading and trailing ASCII whitespace (space, tab, CR, LF).
  • rfind: Returns the byte offset of the last needle in hay, or -1.
  • join: Returns the parts concatenated with sep between each pair.
  • repeat: Returns s repeated n times; empty when n <= 0.
↑ ↓ navigate ↵ open