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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!