On Thu, Dec 29, 2011 at 2:18 PM, Giuseppe Sucameli <[email protected]> wrote: > On Thu, Dec 29, 2011 at 11:25 AM, Andreas Neumann <[email protected]> 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 _______________________________________________ Qgis-user mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/qgis-user
