std-method

String::from_utf16_lossy

Decode UTF-16 with replacement characters for malformed sequences. Useful for display, but does not preserve the original malformed data. Expected stdout (not executed): A�B Common mistake: Using lossy decoding for exact round trips.

Formal Syntax & Structure

rust syntaxrust
fn from_utf16_lossy(v: &[u16]) -> String

Working Example

Example Snippetrust
fn main() {    println!("{}", String::from_utf16_lossy(&[0x41, 0xD800, 0x42]));}
Rust Reference