Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Q&A with Qlik - Qlik Cloud Migration: Questions about migrating to Qlik Cloud? Catch the latest replay!
cancel
Showing results for 
Search instead for 
Did you mean: 
AquaCapriLyn
Contributor II
Contributor II

How to remove leading zeros without removing the zeros in the middle and end

Hello, I am trying to remove leading zeros from the left of a string. I have values that look like 'GH54673045', 000005674505, MFE6453-GW, 000000000532, and 00034002GER. Could you please help me resolve this issue? I tried using the num function but it returns Null values. I also tried the Replace function but it removed the zeros in the middle. For example, 000000004230043 would return 42343 instead of 4230043

Labels (1)
3 Replies
marcus_sommer
MVP
MVP

You may try something like:

if(isnum(myField), mid(myField, findoneof(myField, '123456789')), myField)

rubenmarin
MVP
MVP

Hi, if there are no spaces in the codes you can convert all zeros to spaces, use ltrim to remove the initial spaces and convert again spaces to zeros:

Replace(LTrim(Replace('FieldName','0', ' ')),' ', '0')

You can also convert first all spaces to a non-used character and then return it back, like:

Replace(Replace(LTrim(Replace(Replace('FieldName',' ','~'),'0', ' ')),' ', '0'),'~',' ')

If after the fisrt zero will be always a number you can use:

Mid('FieldName',FindOneOf('FieldName','123456789'))

Else you can use:

Mid('FieldName',FindOneOf(Upper('FieldName'),'123456789.-_ABCDEF...')) // complete with all possible characters except zero.

MarcoWedel
MVP
MVP

another way to start at the first character other than 0:

Mid(String,FindOneOf(String,PurgeChar(String,'0')))