XQuery replace()函式

2019-10-16 23:18:07

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程式來驗證結果。