'How to trim whitespaces from head and tail of a string? [duplicate]

How to trim whitespaces from head and tail of a string (&str) in Rust ?

let a = " Some text here   ";


Solution 1:[1]

By calling trim(). Like,

let a = " Some text here   ";
println!("'{}'", a.trim());

Outputs

'Some text here'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Elliott Frisch