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"?

2
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')

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