How to get file extension in Marklogic Server?

╄→尐↘猪︶ㄣ 提交于 2019-12-25 04:29:09

问题


I want to get the file extension of uploaded file in Marklogic server. I know how to get the file name. But that gives filename plus extension like new.txt. But I want only extension not the full file name. How can I get just the file extension ?


回答1:


There are many methods of getting file extensions from filename. For instance you can use functx:substring-after-last($filename, '.') or other methods (fn:substring-after) of getting substring after dot. Please see: xqueryfunctions.com

P.S. fn:tokenize($filename, '\.')[fn:last()]




回答2:


I often use the following replace:

fn:replace("c:\a\b\c.d.e.txt", '^(.*\.)?([^\.]+)$', '$2')

But using functx is a good idea too, as suggested by Andrew. A copy of the functx library is distributed as part of the latter versions of MarkLogic. Just add the following import to get them available:

import module namespace functx = "http://www.functx.com" at "/MarkLogic/functx/functx-1.0-nodoc-2007-01.xqy";

HTH!




回答3:


Just for variety, yet another expression that produces the extension :) :

reversed-string(substring-before(reversed-string($filePath), '.'))

where reversed-string($s) can be defined as:

codepoints-to-string(reverse(string-to-code-points($s)))

So the whole expression with the substitution is:

codepoints-to-string(
             reverse(
              string-to-codepoints(
               substring-before(codepoints-to-string(reverse(string-to-codepoints($filePath))),
                               '.')
                                   )
                     )
                              )


来源:https://stackoverflow.com/questions/11290464/how-to-get-file-extension-in-marklogic-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!