[Qgis-user] New Labeling: conditional labels

Giuseppe Sucameli sucameli at faunalia.it
Thu Dec 29 06:35:20 PST 2011


On Thu, Dec 29, 2011 at 2:18 PM, Giuseppe Sucameli <sucameli at faunalia.it> wrote:
> On Thu, Dec 29, 2011 at 11:25 AM, Andreas Neumann <a.neumann at carto.net> wrote:
>>What I do not understand is why I need the *-1 (multiplier).
>
> I usually use -1 in python to get the entire string
...
> The function help says:
> substr(string,startpos,length)
> so we need to use the string length, but also the startpos values
> starts from 1, not 0... (and the help doesn't help to understand it).

looking at the code, here's what the susbstr function calls:
string.mid( startpos -1, length )

Now looking at QString.mid() [1] I can confirm that
using the susbstr function:
startpos starts from position 1 (not 0) and
if length is -1 then all chararcters available from startpos are
returned.

So you can use either substr(id, 1, (id > 0)*-1) or
substr(id, 1, (id > 0)*length(id)), both are valid and working syntax.

I think we should improve also the help to add those informations.

Regards.

[1] http://developer.qt.nokia.com/doc/qt-4.7/qstring.html#id-71632fd3-c671-4ae0-9791-bce0d200b511

-- 
Giuseppe Sucameli



More information about the Qgis-user mailing list