how do i get the last 3 letters of a string
· #1how do i get the last 3 letters of a string
how do i get the last 3 letters of a string
Last3 := Copy(S, Length(S) - 2, 3);or with the helper from StrUtils: RightStr(S, 3).
ok that works for photo.png but for picture.jpeg it gives peg
It gives peg because the last three letters of picture.jpeg are peg. The code is right. I suspect the question isn't.
What are you actually trying to find out?
the letters after the dot
That's the file extension, and it has its own function:
Ext := ExtractFileExt('picture.jpeg'); // '.jpeg', the dot includedIt works however long the extension is. Now, one more time: what do you want the extension for?
to know if the file is a picture
There it is. Three questions deep. This has a name: you asked about your solution (last three letters) when you needed help with your problem (is it a picture).
function IsPicture(const FileName: string): Boolean;
begin
case LowerCase(ExtractFileExt(FileName)) of
'.png', '.jpg', '.jpeg', '.gif', '.bmp': Result := True;
else
Result := False;
end;
end;LowerCase matters, because cameras love to write .JPG.
Next time, start with the last sentence. "I want to know if a file is a picture." You'd have had this in one reply.
Read the error message. Then read it again.
ok
how do i get the first 4 letters of a string
What for.
Forum rules 1 to 10 apply. Yes, to you.
...to know if a link starts with http
S.StartsWith('http'). We're getting faster at this.
Forum rules 1 to 10 apply. Yes, to you.