XQuery replace()函數

replace()函數用給定的字串替換匹配的輸入字串。

語法

replace($input, $regex, $string)

輸入參數

  • $input - 輸入字串。
  • $regex - 正則運算式。
  • $string - 要替換原始字串的字串。

示例

XQuery運算式 -

let $input := 'Chapter 1 ... Chapter 2'
return ( replace($input, "Chapter (\d)", "Section $1.0"))

輸出結果如下所示 -

Section 1.0 ... Section 2.0

驗證結果
要測試上述函數,用上面的XQuery運算式替換books.xqy(在XQuery環境設置章節中有說明)的內容,並執行XQueryTester java程式來驗證結果。


上一篇: XQuery正則運算式 下一篇: XQuery自定義函數