[Qgis-user] How to split string values with separator

Alexandre Neto senhor.neto at gmail.com
Wed Feb 3 09:19:27 PST 2016


I believe you need to do a custom function for that, you can use the
function editor and add this:

@qgsfunction(args='auto', group='Custom')
def split(string, separator, index, feature, parent):
    return string.split(separator)[index]

And you use it like this:
split("FieldName",',',1) --> cat
split("FieldName",',',2) --> spider

Alexandre Neto



Piotr Kania <p.kania at op.pl> escreveu no dia quarta, 3/02/2016 às 16:56:

> Hi!
>
> I try to find "Qgis way" to achieve the same as those  arcmap field's
> calculator command: SPLIT( [FieldName],",")(0) - in that case "," is a
> separator, so from a string 'dog,cat,spider' I will get 'dog' - as it is
> the first element, counted as "zero" - 'cat' is number 1, 'spider'
> number 2 etc. So:
>
> SPLIT( [FieldName],",")(1)     ->     'cat'
> SPLIT( [FieldName],",")(2)     ->     'spider'
>
> Thanks for any response
>
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user

-- 
Alexandre Neto
---------------------
@AlexNetoGeo
http://sigsemgrilhetas.wordpress.com
http://gisunchained.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20160203/2d23f12e/attachment.html>


More information about the Qgis-user mailing list