Beta

Replace the extension

Description:

We define a filename's extension as the substring following the last occurence of '.' in it.

Examples:

  • "file1.txt" -> "txt"

  • "file2.abc.ijk" -> "ijk"

  • "file3" -> ""

Your task is to implement the function replace_extension. This function replaces the string parameter's original extension with new_ext, and returns the result:

* replace_extension("file", "txt") -> "file.txt"

* replace_extension("file.abc.markdown", "md") -> "file.abc.md"

* replace_extension("file.a.b.c.d.e.f.g.h.i", "a") -> "file.a.b.c.d.e.f.g.h.a"

* replace_extension("file.txt", "") -> "file"

* replace_extension(".file.hidden", "abc") -> ".file.abc"

Notes:

  • If any of the parameters is NULL, the function's output should be NULL.

  • Filenames which are not 'valid' (containing \, /, or :) should be treated, and the function must return NULL in such cases.

Strings
Fundamentals

Similar Kata:

Stats:

CreatedNov 4, 2017
PublishedNov 4, 2017
Warriors Trained183
Total Skips35
Total Code Submissions806
Total Times Completed37
C Completions37
Total Stars6
% of votes with a positive feedback rating83% of 29
Total "Very Satisfied" Votes19
Total "Somewhat Satisfied" Votes10
Total "Not Satisfied" Votes0
Total Rank Assessments27
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • marrakchino Avatar
  • Voile Avatar
Ad