1

I'm looking for a QGIS function to remove the first n digits on a field attribute table using QGIS string function. For exemple I have the following string in a QGIS attribute table:

742-004-SRV Superficie : 12780

My aim is to remove the first 12 characters. How to achieve this with QGIS?

  • So you want to turn 742-004-SRV Superficie : 12780 into Superficie : 12780? – Joseph May 18 '17 at 14:22
  • Hi Joseph, yes exactly! – user24401 May 18 '17 at 14:34
3

You can use substr.

So:

substr(  "Field" , 13,  length( "Field"))

So this grabs everything from the 13th to the Nth character, with the Nth being the lenght of the field.

  • 1
    Nicely done! Can also use right( "field", length("field" ) - 12) which is essentially the same :) – Joseph May 18 '17 at 14:42
  • Have you actually tested this? Looking at the definition of substr in QGIS, the parameters are input_string, startpos, and length (integer representing length of string to extract). So the last parameter should be length("Field") - 13 + 1 – TJ Rockefeller May 18 '17 at 14:46
  • @TJRockefeller - Hmm, QGIS disagrees :) – Joseph May 18 '17 at 14:56
  • @Joseph either I'm blind (more likely) or you changed your comment. I didn't see you were doing length - 12 for some reason I thought it was just 12. – TJ Rockefeller May 18 '17 at 14:59
  • @TJRockefeller - No problem (FYI, if someone changes their comment, you can see a pencil icon next to it which can tell you how many times the comment has been edited). Like this :) – Joseph May 18 '17 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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