Question: OCaml Write a function newFileName : string -> string -> string such that a call (newFileName oldFileName newExtension) returns oldFileName but with the new extension.
OCaml
Write a function newFileName : string -> string -> string such that a call (newFileName oldFileName newExtension) returns oldFileName but with the new extension. For example, the call (newFileName "MyFile.java" "class") should return the string "MyFileName.class". The input file name may have zero or more dots.
- The call (newFileName "MyFile" "anything") (i.e., with no dots) should return just "MyFile";
- The call (newFileName "My.File.java" "class") should return "My.File.class" (i.e., only the rightmost dot matters);
- The call (newFileName "MyFile." "class") should return "MyFile.class", i.e., a trailing dot with no actual file extension still gives the new extension.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
