DEV Community

Discussion on: Daily Challenge #46 - ???

Collapse
 
room_js profile image
JavaScript Room

This one works for me. Since Bash doesn't support the global flag for regular expressions I had to iterate over the input string...

removeQuestionMark () {
    result=""
    while read -n 1 char ; do
        if [ "$char" != "?" ] ; then
            result="$result$char"
        fi
    done <<< $1
    echo $result
}

removeQuestionMark "h?e?l?l?o?" # prints "hello"
Collapse
 
gypsydave5 profile image
David Wickes

Try tr instead. 😁