Description
The functx:insert-string function inserts a string ($stringToInsert) into another string ($originalString) at a specified position (which is 1-based). If the position is greater than the length of $originalString, it concatenates $stringToInsert at the end.
Arguments and Return Type| Name | Type | Description |
$originalString |
xs:string? |
the original string to insert into |
$stringToInsert |
xs:string? |
the string to insert |
$pos |
xs:integer |
the position |
| return value |
xs:string |
XQuery Function Declaration| See XSLT definition. | | XQuery Syntax for July 2004 - January 2007 (1.0): |
|---|
declare namespace functx = "http://www.functx.com";
declare function functx:insert-string
( $originalString as xs:string? ,
$stringToInsert as xs:string? ,
$pos as xs:integer ) as xs:string {
concat(substring($originalString,1,$pos - 1),
$stringToInsert,
substring($originalString,$pos))
} ; | | XQuery Syntax for May 2003: |
|---|
declare namespace functx = "http://www.functx.com"
define function insert-string
( $originalString as xs:string? ,
$stringToInsert as xs:string? ,
$pos as xs:integer ) as xs:string {
fn:concat(fn:substring($originalString,1,$pos - 1),
$stringToInsert,
fn:substring($originalString,$pos))
} |
Examples| XQuery Example | Results |
|---|
functx:insert-string('xyz','def',2)
|
xdefyz
|
functx:insert-string('xyz','def',5)
|
xyzdef
|
functx:insert-string('xyz','',2)
|
xyz
|
functx:insert-string('','def',2)
|
def
|
See AlsoHistory |
|