[][src]Function utf8_slice::slice

pub fn slice(s: &str, begin: usize, end: usize) -> &str

Fetches a slice of a string from a begin to an end index taking into account utf8/unicode character indices.


  • s - An input string to take the slice from
  • begin - Where the slice begins
  • end - Where the slice ends


let s = "The 🚀 goes to the 🌑!";

let rocket = utf8_slice::slice(s, 4, 5);
// Will equal "🚀"


  • Will return an empty string for invalid indices *