1

I am trying to find a solution to split attributes into two fields at a specific character, slash ("/") in that case.

I tried with How to split a text attribute by characters in QGIS 2.6.0, but I did not succeeded.

enter image description here

I want this:

![enter image description here


I got this after your function, @Kazuhito

enter image description here

1
  • 1
    Given edits made, I hope reopen vote works. In the meantime, please try to_int(left("FIELD", strpos( "FIELD" , '[/]')-1)) and to_int(right("FIELD", length( "FIELD" ) - strpos( "FIELD", '[/]')))
    – Kazuhito
    Feb 22, 2018 at 14:21

1 Answer 1

5

@Kazuhito is basically right, you just need to add a condition to correctly fill "Field2". Try this for "Field1":

to_int( left( "FIELD", strpos( "FIELD" , '[/]' ) - 1 ) ) 

and this for "Field2":

if ( strpos( "FIELD" , '[/]') > 0, 
to_int( right( "FIELD", length( "FIELD" ) - strpos( "FIELD", '[/]' ) ) ), 
NULL)
4
  • I am looking to do this exact thing in an ArcGIS Online map. Any ideas? I am working with a view that has combined info on the same asset, for instance pipe materials. They are listed in a single attribute, separated by a pipe ( | ). Apr 1, 2020 at 18:18
  • Given that you have two new attribute fields, called e.g. field_1 and field_2 and your original field called original, use the Field Calculator and do this for field_1: !original!.split("|")[0], and for field_2: !original!.split("|")[1]. If there is additional whitespace before and after the pipe, include that in the split().
    – s6hebern
    Apr 2, 2020 at 8:20
  • Except for I am unable to perform a field calculate on a view. Any other ideas? Apr 2, 2020 at 17:06
  • I have no experience with ArcGIS online. But if you cannot calculate attributes there, this task might become difficult anyway. Maybe ask a separate question on that specific topic.
    – s6hebern
    Apr 3, 2020 at 11:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.