1

I have a "field" with string values like

field new field
3 0003
5 0005
22 0022
999 0999

What is the right expression for the QGIS Field calculator to get a 4-character string-field like "new field"?

Taras
  • 32,823
  • 4
  • 66
  • 137
Enzo Baldini
  • 2,327
  • 1
  • 15
  • 29

1 Answers1

2

in Field calculator "lpad" does what you want:

Returns a string padded on the left to the specified width, using a fill character. If the target width is smaller than the string's length, the string is truncated.

Syntax: lpad(string,width,fill)

so in your case it would be:

lpad("Your_field_name",4,'0')
sn1ks
  • 2,982
  • 12
  • 28