Skip to content

String

Module: std.string
Source: std/string.zn

Usage Example

use std.string;
fn main() {
let text = String.from("hello");
text.push_str(" world");
@println("{}", text);
}

String

Dynamic heap-allocated string


Fields:

ptr: [*]char,
_len: usize,
_capacity: usize,

Constructors:

pub fn new() Self;
pub fn with_capacity(capacity: usize) Self;
pub fn from(value: []const char) Self;
pub fn from_cstr(value: [*]const char) Self;
pub fn from_raw_parts(ptr: *void, len: usize, capacity: usize) Self;
pub fn from_list(value: *const List[char]) Self;

Getters:

pub fn capacity(*const self) usize;
pub fn is_empty(*const self) bool;
pub fn get(*const self, index: usize) Option[char];
pub fn get_ptr(*const self, index: usize) Option[*char];
pub fn contains(*const self, value: char) bool;
pub fn contains_str(*const self, value: []const char) bool;
pub fn contains_cstr(*const self, value: [*]const char) bool;
pub fn find(*const self, value: char) Option[usize];
pub fn find_str(*const self, value: []const char) Option[usize];
pub fn find_cstr(*const self, value: [*]const char) Option[usize];
pub fn to_list(*const self) List[char];
pub fn trim(*const self) []const char;
pub fn trim_start(*const self) []const char;
pub fn trim_end(*const self) []const char;
pub fn split(*const self, delim: char) List[String];

Mutations:

pub fn push(*self, value: char);
pub fn push_str(*self, value: []const char);
pub fn push_string(*self, value: *Self);
pub fn pop(*self) Option[char];
pub fn remove(*self, index: usize) Option[char];
pub fn set(*self, index: usize, value: char) Option[char];
pub fn to_uppercase(*self);
pub fn to_lowercase(*self);
pub fn replace(*self, from: [*]const char, to: [*]const char);
pub fn reverse(*self);
pub fn clear(*self);
pub fn truncate(*self, new_len: usize);

Parsing:

pub fn parse_i32(*const self) Option[i32];
pub fn parse_i64(*const self) Option[i64];
pub fn parse_u32(*const self) Option[u32];
pub fn parse_u64(*const self) Option[u64];
pub fn parse_f32(*const self) Option[f32];
pub fn parse_f64(*const self) Option[f64];

Interfaces:

  • core.ops : Clone, Drop, Eq, Hash, Index, IndexPtr, Sliceable
  • core.io : Display, Debug, StrWriter