2012-07-02 51 views

回答

2

有很多從文件名獲取文件擴展名的方法。例如,你可以使用functx:substring-after-last($filename, '.')或其他方法(fn:substring-after)獲得點後的子串。請參閱:xqueryfunctions.com

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

+1

不應該是'fn:tokenize($ filename,'\。')[fn:last()]'? – grtjn

+0

是的,你是對的。第二個參數採用正則表達式。謝謝。 –

+0

謝謝@AndrewOrlov –

1

我經常使用下面的替換:

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

但使用functx是一個好主意太,由安德魯建議。 functx庫的副本作爲MarkLogic後期版本的一部分進行分發。只需添加下面的導入,讓他們提供:

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

HTH!

0

只爲多種,但其產生的延伸:)另一種表達:

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

其中reversed-string($s)可以被定義爲:

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

所以用替換整個表達式是:

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