Extract file extension: Difference between revisions

(→‎{{header|Racket}}: Several Improvements)
Line 236:
fileExt("file.odd_one") println
</pre>
 
=={{header|Python}}==
Uses [https://docs.python.org/3/library/os.path.html#os.path.splitext os.path.splitext] and the extended tests from the Go example above.
 
<lang python>Python 3.5.0a1 (v3.5.0a1:5d4b6a57d5fd, Feb 7 2015, 17:58:38) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import os
>>> tests = ["picture.jpg",
"http://mywebsite.com/picture/image.png",
"myuniquefile.longextension",
"IAmAFileWithoutExtension",
"/path/to.my/file",
"file.odd_one",
# Extra, with unicode
"café.png",
"file.resumé",
# with unicode combining characters
"cafe\u0301.png",
"file.resume\u0301"]
>>> for path in tests:
print("Path: %r -> Extension: %r" % (path, os.path.splitext(path)[-1]))
 
Path: 'picture.jpg' -> Extension: '.jpg'
Path: 'http://mywebsite.com/picture/image.png' -> Extension: '.png'
Path: 'myuniquefile.longextension' -> Extension: '.longextension'
Path: 'IAmAFileWithoutExtension' -> Extension: ''
Path: '/path/to.my/file' -> Extension: ''
Path: 'file.odd_one' -> Extension: '.odd_one'
Path: 'café.png' -> Extension: '.png'
Path: 'file.resumé' -> Extension: '.resumé'
Path: 'café.png' -> Extension: '.png'
Path: 'file.resumé' -> Extension: '.resumé'
>>> </lang>
 
=={{header|Racket}}==
Anonymous user