How to use PadLeft with Replace(",","").Replace(".","") correctly

Hello. I have a field inside a Mainframe that i need to automate, and this field contains, by default, nine zeros (0) 000000000 this way. For each client, i have a salary limit that I must put in this field, but the zeros can’t be deleted, they are positional. Example: if i have a 5000 limit, it must be this way 000005000, 9 numbers format will always stay, so i need to use PadLeft to fullfill the left side with enough zeros, and Replace to remove commas and dots from the salary.

Without replace function, the padleft works but it puts dots and commas, that are not accepted in the field, and when I try this way(for 5000 salary limit) : limit.PadLeft(9,CChar(β€œ0”)).Replace(β€œ,”,β€œβ€).Replace(β€œ.”,β€œβ€) it simply give me this result:


Giving me the wrong limit as the real limit is 5000 not 500000.

How do i fix this?

Hi @comercial

I guess you should first remove the . and , and then use padleft


For easier conversions I’m assuming that we can convert it to Int

Hope it helps!

Happy Automation

1 Like


If comma is thousand separator and dot is decimal point, the following expression might be better.




Hi @comercial

To correctly format the salary limit while preserving the leading zeros and removing commas and dots, you can use the following approach:

Dim limit As Integer = 5000
Dim limitString As String = limit.ToString()
limitString = limitString.Replace(β€œ,”, β€œβ€).Replace(β€œ.”, β€œβ€)
limitString = limitString.PadLeft(9, "0"c)


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