Get only 6 digit number from datatable

i have one excel and i stored all data in datatable so now i want only 6 digit numbers if we gt 7 or 8 digits then want to remove from it and if i found 1digit then have to add 00000 before 1 digit and if i found 23 then have to add 0000 before 23 so inshort i want less than 6.
here attach my excel and my column name is(“Cheque no”) data.xlsx (20.2 KB)

Hi @suraj23

go throughout this training this might help to build such a logics.

1 Like

You can use PadLeft for padding zeroes if string length is less than 6 digits and get last 6 digits only (if string length is more than 6),

Result = Your_String.PadLeft(6, '0').GetLast(6)

Hi @suraj23,

Find attached solution, inside i have added comments to each step i have used. Revert back if you have doubt regarding it. Here i have used simple linq query and string manipulation to achieve your requirement. (33.1 KB)

have tried this but still these value came in O/P
i want only 6 or less than digit numbers

A small typo in the given expression. Please use below expression -

str = Your_String.PadLeft(6, '0')
result = str.SubString(str.Length -6)

thanks Ragu9060

its working fine with write .xlsx file but when i write in .CSV all 0000 disappears


What ever formatting you do in excel will vanish when it is converted to csv, try setting column data type as text before converting to csv

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