Because http://store.aqa.org.uk/qual/newgcse/pdf/AQA-4695-W-SP.PDF
doesn't have a \Q.PDF\E
on the end. In a string literal, \\
gives you a backslash. So "\\Q.PDF\\E"
is \Q.PDF\E
— a backslash, followed by a Q
, followed by a dot, followed by PDF
, followed by another backslash, followed by E
.
If you want to see if the string ends with .PDF
, just use
if (!str.endsWith(".PDF"))
Of course, that's case-sensitive. If you want it to be case-insensitive, probably:
if (!str.toLowerCase().endsWith(".pdf"))