Remove filename extension in Java

后端 未结 10 2241
你的背包
你的背包 2020-12-09 08:48

(Without including any external libraries.)

What\'s the most efficient way to remove the extension of a filename in Java, without assuming anything of the f

10条回答
  •  萌比男神i
    2020-12-09 09:46

    Regex for these things are "fast" enough but not efficient if compared to the simplest method that can be thought: scan the string from the end and truncate it at the first dot (not inclusive). In Java you could use lastIndexOf and substring to take only the part you are interested in. The initial dot should be considered as a special case and if the last occurrence of "." is at the beginning, the whole string should be returned.

提交回复
热议问题