SUBTR is defined to behave like fn:substring from XQuery/Xpath functions and operators:

http://www.w3.org/TR/xpath-functions/#func-substring

and that has the example:

"""
fn:substring("12345", 5, -3) returns "".

Characters at positions greater than or equal to 5 and less than 2 are selected.
"""

To get the last two,

SUBSTR("abcd",STRLEN("abcd")-1, 2)

or

REPLACE("abcd", "^.*(?=..)", "")

(and probably other ways.)

        Andy

On 29/04/14 15:11, Jürgen Jakobitsch wrote:
hi,

i just have checked a couple of implementations regarding the behaviour of
negative length for SUBSTR sparql function. what i tried to achieve is
to get
the last two characters of a string, but this doesn't really work anywhere.

a use case : number padding

example :

SELECT ?padded WHERE {
   ?s ?p ?num FILTER(isNumeric(?num) && ?num<10000000) .
   BIND(SUBSTR(CONCAT("0000000", ?num),STRLEN(?num),-7) AS ?padded)
}

any thoughts?

wkr jürgen


| Jürgen Jakobitsch,
| Software Developer
| Semantic Web Company GmbH
| Mariahilfer Straße 70 / Neubaugasse 1, Top 8
| A - 1070 Wien, Austria
| Mob +43 676 62 12 710 | Fax +43.1.402 12 35 - 22

COMPANY INFORMATION
| web       : http://www.semantic-web.at/
| foaf      : http://company.semantic-web.at/person/juergen_jakobitsch
PERSONAL INFORMATION
| web       : http://www.turnguard.com
| foaf      : http://www.turnguard.com/turnguard
| g+        : https://plus.google.com/111233759991616358206/posts
| skype     : jakobitsch-punkt
| xmlns:tg  = "http://www.turnguard.com/turnguard#";


Reply via email to