[QGIS-Developer] substr expression 1-based? Others too?

Richard Duivenvoorde rdmailings at duif.net
Mon May 8 06:31:20 PDT 2017

Hi Devs,

Trying to create a rule based style I encountered/used the 'substr'
function to find the first character of a field.

Isn't it strange that this function is one based while in all languages
I know this kind of function(s) are zero-based?

now it is:
substr('Hello',0,1) returns ''
while I expected it to return 'H'
substr('Hello',1,1) returns 'H'

in QGIS3 there is also:
substr('Hello',-1,1) returns 'o'  # ok

Are more functions one-based instead of (the normal?) zero-based?

Is it an idea to bring the expression(s) inline with other programming

Or is there a special reasoning not to do this?



More information about the QGIS-Developer mailing list