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"?
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"?
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')
lpad("field", 4, 0)– Taras Jul 28 '21 at 11:41