Need a basename function in Javascript

后端 未结 19 2028
野性不改
野性不改 2020-11-29 02:44

I need a short basename function (one-liner ?) for Javascript:

basename(\"/a/folder/file.a.ext\") -> \"file.a\"
basename(\"/a/folder/file.ext\") -> \"f         


        
19条回答
  •  长情又很酷
    2020-11-29 03:08

    if your original string or text file contains single backslash character, you could locate it by using '\'. in my circumstance, i am using javascript to find the index of "\N" from a text file. and str.indexOf('\N'); helped me locate the \N from the original string which is read from the source file. hope it helps.

提交回复
热议问题