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.

3

2 Answers 2

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))
1
  • 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
    Commented Feb 12, 2019 at 8: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.

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.