If statement executing when comparing equality of hyphen

Hi I am wondering what I am doing incorrectly here,

somestring = "2021_10_20-sess05-spk_M_C_010.pdf"

if somestring[11] != "-"
    @show somestring[11],"incorrect"
end

>>>
("-", incorrect)

It shouldnt be executing since the 11th characters of the string is equal to “-” but it does. I have also tried with !== resulting in the same result.

What you want is

julia> if somestring[11] != '-'
           @show somestring[11],"incorrect"
       end

see:

julia> somestring[11]
'-': ASCII/Unicode U+002D (category Pd: Punctuation, dash)

julia> typeof("-")
String

Edit: @stevengj is right, corrected.

2 Likes

No need to chall Char here — '-' is already a Char.

3 Likes