I'm trying to label correctly a set of points in my map. They refer to localities and water analyses for those places in Spain. But the information in one of the fields is duplicated, it's written two times. I'm using QGIS 2.18

point with wrong text

I'm trying to delete the duplicate text from a field in my Attribute table, but so far, I've not been able to find the right expression. The Field is called Municipio.
I've tried with the expression: replace ( "Municipio", 'Municipio', ' ' ) but it's not working.

Any idea ?

Points with problems from Attribute table


1 Answer 1


To retain only the first part of a duplicated Municipio field, try an expression below in the Field Calculator.

CASE WHEN left("Municipio", strpos("Municipio", '\\s')-1) 
          left(replace("Municipio", left("Municipio", strpos("Municipio", '\\s')), ''), 
               strpos("Municipio", '\\s')-1)
THEN left("Municipio", strpos("Municipio", '\\s')-1)
ELSE "Municipio"


  • Not sure how you would like to handle it if we have triple words... this expression only keeps the first.
  • This does not work well with a Municipio which includes space in its name.

enter image description here

  • @Kazuhito I just want miserably to extend your answer. I suppose @prigual needs encoding adjustment, e.g. UTF-8, which may show letters instead of the question marks.
    – Taras
    Commented Aug 20, 2018 at 12:33
  • @Kazuhito. Yes, the expression from Kazuhito it's working. I only need to keep the first name. I don't understand the expression but it works fine.( I'll study the pexression later :). And yes, I still have a problem with the font, like the question marks, but I may ask another question for that. It's more clear for the forum, thanks both of you
    – prigual
    Commented Aug 20, 2018 at 14:34

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.