I'm working on a program in pike and looking for a method like the endswith() in python- a method that gives me the extension of a given file. Can someone help me with that? thank you
Asked
Active
Viewed 57 times
3 Answers
1
Python's endswith() is something like Pike's has_suffix(string s, string suffix):
has_suffix("index.html", ".html");
Reference: http://pike.lysator.liu.se/generated/manual/modref/ex/predef_3A_3A/has_suffix.html

Yyttsa
- 59
- 1
- 5
0
extract the end of the string, and compare it with the desired extension:
"hello.html"[<4..] == ".html"
(<4
counts from the end of the string/array)

eMBee
- 793
- 6
- 16
0
If you want to see what the extension of a file is, just find the last dot and get the substring after it, e.g. (str/".")[-1]
If you just want to check if the file is of a certain extension, using has_suffix() is a good way, e.g. has_suffix(str, ".html")

khora
- 1
- 1