Remove the last character from a string

Hello

I saw that the function “chop” removes the last character of a given string. How to do the same for the first one ?

Thank’s

Michael.

1 Like

Perhaps:

julia> snip(s::String) = s[nextind(s,1):end];

julia> snip("αβγ")
"βγ"
1 Like

Sure, that’ll do. Thank’s !

This remove first character not last?

That was the question, you can use chop for the last character.

Thanks a lot, I was in need of it now, to convert jpg files into bmp, and done with this code:

using Images, FileIO, ImageMagick
files = cd(readdir, pwd())
for f in files
    if occursin(r".*\.jpg\z", f) == true
        img = load(f)
        fn = chop(f, tail=4)
        save("rawdata/$fn.bmp", img)
    end
end
1 Like

You can also see splitext which is made for that purpose.

2 Likes