How can I in QGIS through Expression calculator remove leading zeroes i.e. the 0
leading from a string?
Original_Value | New_Value |
---|---|
09 | 9 |
0150 | 150 |
09850 | 9850 |
054a23 | 54a23 |
5837 | 5837 |
Something like the example above.
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityThe following should be working :
regexp_replace("field_to_modify",'\\A0','')
Only if your aim is to strip a (=one) leading zero ...
\A
declares this rexegg.com/regex-anchors.html#A
Simply you can use the regexp_replace()
function in the following expression:
regexp_replace("FieldName", '^0', '')
'^0'
means select the 0
that is located at the beginning of string.
"FieldName"
is the input field that you want to remove the zero from.
Here is the output:
I would also suggest making a number attribute column and populating this new column with "OLD_Column" * 1
Another way, if there are only numeric characters in your field and you have multiple leading zeros, is to convert the field to an integer using to_int("FIELD_NAME")
so 0000535
becomes 535
.