DEV Community

Discussion on: Daily Challenge #206 - Pound Means Backspace

Collapse
 
idanarye profile image
Idan Arye

Rust:

pub fn clean_string(text: &str) -> String {
    let mut result = String::new();
    for ch in text.chars() {
        if ch == '#' {
            result.pop();
        } else {
            result.push(ch);
        }
    }
    result
}

fn main() {
    assert_eq!(clean_string("abc#de##c"), "abc");
    assert_eq!(clean_string("abc####dhh##c#"), "d");
    assert_eq!(clean_string("Thee# Empires# SS#tateBuildingg#"), "The Empire StateBuilding");
}

Too easy...

Collapse
 
qm3ster profile image
Mihail Malo

Maybe match ch :v

Collapse
 
idanarye profile image
Idan Arye

Why?

Thread Thread
 
qm3ster profile image
Mihail Malo

Just to show off