Skip to content
Rust

std::string::String API Reference

Rust's String — a growable, owned UTF-8 encoded string type, heap-allocated and mutable.

By EZ4Code Team

String

A UTF-8-encoded, growable string. It is the owned version of &str.

String::new() -> String

Creates a new empty String.

Returns: String

String::from(s: &str) -> String

Converts a &str into a String, copying the data.

Returns: String

s.push_str(s2: &str)

Appends a given string slice onto the end of this String.

Returns: ()

s.push(ch: char)

Appends the given char to the end of this String.

Returns: ()

s.len() -> usize

Returns the length of this String, in bytes, not chars or graphemes.

Returns: usize

s.as_str() -> &str

Extracts a string slice containing the entire String.

Returns: &str

s.replace(from: &str, to: &str) -> String

Replaces all matches of a pattern with another string, returning a new String.

Returns: String

More Rust API References