# What's the file extension?

Your challenge is to find the file extension of a provided filename:

hi.txt -> txt or .txt
carrot.meme -> meme or .meme
lol (undefined behavior)
what..is..this..file -> file or .file
.bashrc -> bashrc or .bashrc
T00M@n3KaPZ.h0wC[]h -> h0wC[]h or .h0wC[]h
agent.000 -> 000 or .000

Try it online!

# ActionScript2.0, 42 bytes

function a(b){trace(b.split(".").pop());};

Technically the ;s aren't required for it to compile, at least in JPEXS, but it's good practice. Call:

a("a.b");

(traces "b")

• Oh, OK. Looking at other examples, I didn't realise that. ActionScript doesn't really have a way to take inputs, so sure, delete this. Unless... – Jhynjhiruu Rekrap Mar 9 '18 at 20:28
• Looks good. Happy golfing. – 0 ' Mar 9 '18 at 20:36
• Awesome. By the way, putting the trace() inside the function is shorter when considering outputting, but then it requires a string be included when calling the function - is that allowed? – Jhynjhiruu Rekrap Mar 9 '18 at 20:39
• I'm not quite sure what you mean by it requiring a string to be included when calling the function as I hardly know any Actionscript. In general it's allowed to mix and match any of the default allowed input and output methods. – 0 ' Mar 9 '18 at 20:54
• function a(b){trace(b.split(".").pop());}; prints the output and is only 42 bytes, but calling the function would be a("a.b"); ActionScript has syntax very similar to JavaScript, so you can pretty much just read it like JavaScript. – Jhynjhiruu Rekrap Mar 9 '18 at 20:55

# Aceto, 6 bytes

r'.:Qp

Try it online!

r       grabs input as string
'.     literal period
:    split string on period
Q   grap bottom item
p  print it

# ><>, 18 bytes

i:0(6$.:"."=?] ro| Try it online! ### How It Works: i:(6$.  Jump to the second line if out of input
:"."=  Else check if the character is a .
?[ And create a new stack if it is
Loop back to the beginning of the line
If it is end of input
ro|  Reverse the current stack once and output, erroring on the EOF (-1)

# Stax, 4 bytes

'./H

Run and debug online!

## Explanation

Split on ., take last part.

# T-SQL, 48 bytes

SELECT RIGHT(F,CHARINDEX('.',REVERSE(F))) FROM T

SQL Fiddle

# SNOBOL4 (CSNOBOL4), 46 bytes

I =INPUT
S	I '.' REM . I	:S(S)
OUTPUT =I
END

Try it online!

Takes the input, then repeatedly replaces it with all the text following the first . until no .s remain, then outputs the value.

# Funky, 26 bytes

s=>(k=s::split".")[(#k)-1]

Try it online!

# Jotlin, 17 bytes

split(".").last()

Full file:

data class Test(val input: String, val output: String)

val test = listOf(
Test("hi.txt", "txt"),
Test("carrot.meme", "meme"),
Test("what..is..this..file", "file"),
Test(".bashrc", "bashrc"),
Test("T00M@n3KaPZ.h0wC[]h", "h0wC[]h"),
Test("agent.000", "000")
)

fun String.f() = split(".").last()

for ((i, o) in test) {
if (o != i.f()) {
throw AssertionError()
}
}

## MBASIC, 129 bytes

1 INPUT F$:F=INSTR(F$,"."):IF F=0 THEN END
2 FOR I=LEN(F$) TO 1 STEP -1:P$=MID$(F$,I,1):O$=P$+O$:IF P$="." THEN PRINT O$:END 3 NEXT Explanation Get a filename. If it doesn't contain a period, bail out. Otherwise, collect letters from right to left to build an output string. When we see a period, print the string. Output ? hi.txt .txt ? .bashrc .bashrc ? T00M@n3KaPZ.h0wC[]h .h0wC[]h # R, 40 26 bytes -14 bytes thanks to J.Doe sub("^.*[.]","",scan(,"")) Try it online! • 26 bytes – J.Doe Oct 27 '18 at 9:16 # Red 9 bytes Suffix? f Assumes file is is in word 'f • Do you have a link to documentation or interpreters for that language? – Nissa Oct 29 '18 at 20:35 • I don't think this does what the challenge asks. The challenge is asking for a program that takes the file name and gives the extension. – Post Rock Garf Hunter Oct 29 '18 at 20:54 # Pepe, 48 bytes rEeeEeEEEeREEeREEEerEEREEEEEEEreererEEEEeEeereee Try it online! # C (gcc), 7760 52 bytes char*f(char*s){for(s+=strlen(s);*--s-46;);return s;} Try it online! -17 bytes from Jonathan Frech -8 bytes by removing i and doing arithmetic on s directly Ungolfed (same strategy): char *extension(char *original) { original = original + strlen(original); while(original[0] != '.') --original; return original; } # Turing Machine But Way Worse, 1315 1287 bytes 0 0 0 1 1 0 0 1 0 1 1 8 0 0 0 1 0 1 2 0 0 1 1 1 1 9 0 0 0 2 0 1 3 0 0 1 2 1 1 a 0 0 0 3 0 1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 0 0 0 F 0 1 G 0 0 1 F 1 1 G 0 0 0 G 0 1 H 0 0 1 G 1 1 H 0 0 0 H 0 1 I 0 0 1 H 1 1 I 0 0 0 I 0 1 J 0 0 1 I 1 1 J 0 0 0 J 0 1 K 0 0 1 J 1 1 K 0 0 0 K 0 1 w 1 0 1 K 1 1 w 1 0 Try it online! Wow, this is big. • Wow this is incredible! – MilkyWay90 Aug 10 '19 at 5:47 ## Emacs, 6 bytes The cursor needs to be at the start of the line containing the string. This will delete the entire line if there's no extension. C-<SPC> C-e C-r . <RET> <BACKSPACE> Explanation: C-<SPC> start a selection C-e go to the end of the line C-r . <RET> search for "." backward <BACKSPACE> delete the selected text (which should be the text before the last ".") # Pushy, 13 bytes K46-$v;F@46+"

Try it online!

\ Implicit: string on stack as character codes
K46-           \ Subtract 46 from each code point, mapping '.' to 0

Try it online!

# Befunge-98 (FBBI), 50 bytes

{v
>~:a`!#v_
--2*86:\$<:u-10_v#
02-u0}>:#,_@   >00

Try it online!

Puts string onto stack, then iterates through it in reverse, putting each new character onto new stack. Once a . is encountered, discard original stack and output new stack in 0gnirts format.

# Forth (gforth), 45 bytes

: f begin 1 -1 d+ s" ."search 0= until type ;

Try it online!

### Code Explanation

: f              \ start a new word definition
begin          \ start an indefinite loop
1 -1 d+      \ remove the first character from the string
s" ."search  \ find the length and starting address of the first substring that starts with '.'
0=           \ check if '.' was found in the string
until          \ end the loop if not
type           \ output the result
;                \ end the word definition

# 33 v1.0, 13 bytes

Gets the file name passed as an argument and prints the extension (without leading '.') to standard output.

1bt'.'ywmcbtp

Explanation:

1b            (Gets the second item in argv, the filename input)
t'.'y       (Splits that by '.')
wmcb   (Gets the last element in the list)
tp (Prints to standard output)

# brainfuck, 45 bytes

,[>,]>+[[-]++[<->------]<---<[->+>+<<]>]>[.>]

Try it online!

# Python & JavaScript, 22 bytes

'x.h'.split('.').pop()

Explanation

I did split the string 'x.h', which is the full file name at the dot and then I did remove the last index in the list (the extension) and this happens to return the value of the removed list item which in my case would be the extension.

Note: This could run on either JavaScript or Python without adaptations

• Welcome to the site! A couple things: rather than hardcoding the x.h, you need to take it as input, as a parameter, or through another allowed input method. Also, this answer requires a read-evaluate-print loop (REPL) in order to work; this must be specified. – Khuldraeseth na'Barya Mar 13 '18 at 0:38
• Welcome to the site! Unfortunately, this is only a snippet, and so is invalid. You can make it into a lambda like this: lambda x:x.split('.').pop(), or Python REPL like this: input().split('.').pop() (input format depends on whether you use Python 2 or Python 3). – Erik the Outgolfer Mar 13 '18 at 12:05