Trait std::str::StrAllocating[src]

pub trait StrAllocating: Str {
    fn into_string(self) -> String;

    fn to_string(&self) -> String { ... }
    fn into_owned(self) -> String { ... }
    fn escape_default(&self) -> String { ... }
    fn escape_unicode(&self) -> String { ... }
    fn replace(&self, from: &str, to: &str) -> String { ... }
    fn to_owned(&self) -> String { ... }
    fn to_utf16(&self) -> Vec<u16> { ... }
    fn repeat(&self, nn: uint) -> String { ... }
    fn lev_distance(&self, t: &str) -> uint { ... }
    fn nfd_chars(&'a self) -> Decompositions<'a> { ... }
    fn nfkd_chars(&'a self) -> Decompositions<'a> { ... }
}

Any string that can be represented as a slice

Required Methods

fn into_string(self) -> String

Convert self into a String, not making a copy if possible.

Provided Methods

fn to_string(&self) -> String

Convert self into a String.

fn into_owned(self) -> String

fn escape_default(&self) -> String

Escape each char in s with char::escape_default.

fn escape_unicode(&self) -> String

Escape each char in s with char::escape_unicode.

fn replace(&self, from: &str, to: &str) -> String

Replace all occurrences of one string with another.

Arguments

  • from - The string to replace
  • to - The replacement string

Return value

The original string with all occurrences of from replaced with to.

Example

fn main() { let s = "Do you know the muffin man, The muffin man, the muffin man, ...".to_string(); assert_eq!(s.replace("muffin man", "little lamb"), "Do you know the little lamb, The little lamb, the little lamb, ...".to_string()); // not found, so no change. assert_eq!(s.replace("cookie monster", "little lamb"), s); }
let s = "Do you know the muffin man,
The muffin man, the muffin man, ...".to_string();

assert_eq!(s.replace("muffin man", "little lamb"),
           "Do you know the little lamb,
The little lamb, the little lamb, ...".to_string());

// not found, so no change.
assert_eq!(s.replace("cookie monster", "little lamb"), s);

fn to_owned(&self) -> String

fn to_utf16(&self) -> Vec<u16>

Converts to a vector of u16 encoded as UTF-16.

fn repeat(&self, nn: uint) -> String

Given a string, make a new string with repeated copies of it.

fn lev_distance(&self, t: &str) -> uint

Levenshtein Distance between two strings.

fn nfd_chars(&'a self) -> Decompositions<'a>

An Iterator over the string in Unicode Normalization Form D (canonical decomposition).

fn nfkd_chars(&'a self) -> Decompositions<'a>

An Iterator over the string in Unicode Normalization Form KD (compatibility decomposition).

Implementors