[MarkLogic Dev General] How to cast a sequence as a string?

Ryan Grimm grimm at xqdev.com
Tue Dec 18 00:51:45 PST 2007


Hi Jim,

I was able to get string-join() to work, here's the code:

fn:string-join(
     let $string := "ABC"
     let $data := (1, 3, 1, 2)
     for $i in $data
     return fn:substring($string, $i, 1)
, "")

Hope that works for you.

--Ryan


Jim.Stock at empolis.com wrote:
> Hi,
> 
> I have a sequence of integers that I iterate through to get a numeric 
> equivalent from a string based on the corresponding position.
> 
> e.g.
> 
> let $string := “ABC”
> 
> let $data := (“1”, “3”, “1”, “2”)
> 
> for $i in $data
> 
> return (
> 
>       (: get the substring that is 1 character long from $string at 
> position $i :)
> 
> fn:substring($string, $i, 1)
> 
> )
> 
> I’m using this to build part of a URL where no spaces are allowed.
> 
> So what I would like is the following string:
> “ACAB”
> 
> But what I’m getting is a sequence
> A C A B
> 
> How can I cast a sequence to a string?
> 
> If I try string-join or similar I get an “invalid coercion” error.
> 
> Thanks in advance for what I’m sure is a simple thing to solve,
> 
> Jim


More information about the General mailing list