How to remove leading zeros from data table column

hello all,

I would like to remove leading zeros from a data table column. please check my data.
leadingzeros
from depost column i want to remove leading zeros. Would you please suggest me how would i achieve this.

Thanks in advance.

Hi @roysupriya21

first read the excel file using read range and store in dt1 variable

  1. Now use invoke code activity with dt1 variable as In/Out argument, the code to used is

dt1.AsEnumerable().ToList().ForEach(Sub(row) row(“Depost”)= CInt(row(“Depost”).ToString))

write the datatable dt1 to excel using write range

Hope it helps
.
Regards,

Nived N
Happy Automation

2 Likes

@roysupriya21,

Follow weblink, check if zeros are running away.
if works, then you have to automate that part before you actually read excel

I did not get any web link . Would please re send .

@roysupriya21,

I’m sorry, here you go,

it is working . Thank you.

1 Like

hello,

I would like to take one more suggestion from you . my actual requirement is I will remove leading zeros only when the length of the string less than or equal 6 in depost column. for more reference I have also added the data.
leadingzeros_1

I will be very humbled if you give me some suggestion.

thanks in advance

Hi @roysupriya21
for this we had to do some modifications in same code as i told above

Modified code

dt1.AsEnumerable().ToList().ForEach(Sub(row) row(“Depost”)= If(row(“Depost”).ToString.Length<=6,CInt(row(“Depost”).ToString),row(“Depost”)))

Try this and let me know if it works

Regards,
Nived N
Happy Automation

1 Like

I did try your code. but it is showing error. please check the screenshot.

Hi @roysupriya21
sorry, there was mistake, i had corrected the code, please look that

Regards,
Nived N
Happy Automation

Thanks a lot . it is working perfectly.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.