2

How to split a "Field" into "Field 1" and "Field 2" when the comma is a separator in the field?

I am using Field Calculator in QGIS.

Taras
  • 32,823
  • 4
  • 66
  • 137
paimo
  • 51
  • 2
  • 5

2 Answers2

4

If you want to use the field calculator, it is quite straightforward. To get everything to the left of your comma use the following expression:

left("myField", strpos("myField", ','))

To get everything to the right of the comma use this expression:

right("myField", length("myField")-(strpos("myField", ',')+1))
MappaGnosis
  • 33,857
  • 2
  • 66
  • 129
  • In both cases, comma remains in a new substring. I assume it should include "-1", i.e. left("myField", strpos("myField", ',')-1) for "myField" values like 'My Street, 1A'. – Taras Feb 12 '19 at 08:10
2

My solution: array_to_string(array_slice(string_to_array( "string.Split.By.Dot",'.'),1,3),'.') => "string.by.dot" Where 1,3 is index of the start and end of slice.

MrXsquared
  • 34,292
  • 21
  • 67
  • 117
kivi_or
  • 21
  • 2