patternrustMajor
Check if a string is empty or blank
Viewed 0 times
stringcheckblankempty
Problem
What's the proper way to check if a string is empty or blank for a) &str b) String? I used to do it by
"aaa".len() == 0, but there should another way as my gut tells me?Solution
Both
This is how they are used:
&str and String have a method called is_empty:- Documentation for &str::is_empty
- Documentation for String::is_empty
This is how they are used:
assert_eq!("".is_empty(), true); // a)
assert_eq!(String::new().is_empty(), true); // b)Code Snippets
assert_eq!("".is_empty(), true); // a)
assert_eq!(String::new().is_empty(), true); // b)Context
Stack Overflow Q#26605224, score: 91
Revisions (0)
No revisions yet.