Reputation: 11728
What is the simplest way to remove all leading zeroes from a string?
Here is something I came up with:
let mut chars = original_str.chars();
let mut res = chars.as_str();
while chars.next() == Some('0') {
res = chars.as_str();
}
Is there something better, in terms of brevity and/or performance?
Upvotes: 5
Views: 1748
Reputation: 42716
fn main() {
assert_eq!("00foo1bar11".trim_start_matches('0'), "foo1bar11");
}
Upvotes: 9