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

underdark
  • 84,148
  • 21
  • 231
  • 413
Frodo
  • 2,407
  • 1
  • 18
  • 36
  • 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 '18 at 14:21

1 Answers1

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)
s6hebern
  • 1,236
  • 10
  • 19
  • 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 ( | ). – Lindsy Hales Bentley Apr 01 '20 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 02 '20 at 08:20
  • Except for I am unable to perform a field calculate on a view. Any other ideas? – Lindsy Hales Bentley Apr 02 '20 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 03 '20 at 11:54