Match the end of a string
Check the letters at the end of the text. The result is true only when those letters match.
endswith
Simple example
Does abc end with c?
Start'abc' · 'c'
Resulttrue
function main()
println(endswith("abc", "c"))
end
main()
true
Advertisements
Everyday examples
A teacher wants PDF files. Does this name end in .pdf?
Start'notes.pdf' · '.pdf'
Resulttrue
function main()
println(endswith("notes.pdf", ".pdf"))
end
main()
true
A music player lists MP3 files. Does the recording have that ending?
Start'rehearsal.wav' · '.mp3'
Resultfalse
function main()
println(endswith("rehearsal.wav", ".mp3"))
end
main()
false
Fragile shelf labels end in -F. Does this one belong there?
Start'12-F' · '-F'
Resulttrue
function main()
println(endswith("12-F", "-F"))
end
main()
true