A white space character is any character or characters that represent horizontal or vertical space in typography. In Rust, we can check if a character is white space using the is_whitespace()
method.
character.is_whitespace()
character
: This is the character we want to check to see if it is a white space.
The is_whitespace()
method returns a Boolean value. If the character is a white space, then the method returns true
. Otherwise, it returns false
.
fn main(){ // create some characters let char1 = 'E'; let char2 = '\u{A0}'; // no-break space let char3 = '\n'; // new line let char4 = 'r'; let char5 = '\u{202F}'; // narrow no-break space // check if characters are white-space println!("{}", char1.is_whitespace()); // false println!("{}", char2.is_whitespace()); // true println!("{}", char3.is_whitespace()); // true println!("{}", char4.is_whitespace()); // false println!("{}", char5.is_whitespace()); // true }
RELATED TAGS
CONTRIBUTOR
View all Courses