Start learning free

LESSON 75 OF 505 · STRINGS - CHALLENGES

File Extension in Go

Practice

Given a file name fileName, return its extension: the part of the name after the last dot.

Split the name at every dot, and the extension is the last of the parts. A name can have more than one dot, like "archive.tar.gz": only what comes after the last dot is the extension. Keep its letters exactly as they are.

 

Example 1:

Input: fileName = "photo.jpeg"
Output: "jpeg"
Explanation: The name has one dot, and "jpeg" comes after it.

Example 2:

Input: fileName = "archive.tar.gz"
Output: "gz"
Explanation: Splitting at the dots gives "archive", "tar" and "gz". The last part, "gz", is the extension.

Example 3:

Input: fileName = "README.MD"
Output: "MD"
Explanation: The extension keeps its upper-case letters.

 

Constraints:

  • fileName has at least one dot, and doesn't start or end with a dot.
  • fileName has no spaces: only English letters, digits, dots, - and _.
STEP 1 OF 2
    Ctrl + Enter to check

    File Extension in Go

    Keep going with Go500+ step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free