06-07-23 10:35 AM
Hi
I am extracting text from Excel which contains leading zeros as well as zeros with the in the text.
I would like to remove the leading zeros only.
Example : 00987098 = 987098
I have looked at regex but it removes all the zeros, is there an easier way to do this ?
Many thanks
Answered! Go to Answer.
11-07-23 07:18 PM
While I would probably cast the string to a number, you could also use the "Regex Replace" action in Blue Prism's "Utility - Strings" VBO with the following parameters:
Pattern: "0*([1-9]\d*)|0"
Replacement Data: "$1"
The only advantage over casting is that it will return a blank value if the string is all zeros.
------------------------------
Micheal Charron
Senior Manager
RBC
America/Toronto
------------------------------
06-07-23 11:00 AM
You can try saving the Data Item in Number Type
06-07-23 11:33 AM
Thanks I will try that
06-07-23 12:08 PM
Hi Rachael,
As the data comes from XL, you could consider changing the data type for that XL column to Number, which would remove leading zeroes. Then you extract the data to your process.
11-07-23 03:06 PM
Hello Rachael,
Right(00987098,6) works on text in Blue Prism. As in Right([OriginalText],6).. But of course you could only use this approach if you knew you always wanted the first 6 characters as read from right.
Otherwise, you would have to use some additional type of logic (like this choice stage) to determine how many characters from the right that you want to keep.
The calculation stage below each choice would look like this.
The calculation stage above the choice just captures the length of the OriginalText to enable the math in the Right() function.
11-07-23 07:18 PM
While I would probably cast the string to a number, you could also use the "Regex Replace" action in Blue Prism's "Utility - Strings" VBO with the following parameters:
Pattern: "0*([1-9]\d*)|0"
Replacement Data: "$1"
The only advantage over casting is that it will return a blank value if the string is all zeros.
------------------------------
Micheal Charron
Senior Manager
RBC
America/Toronto
------------------------------
12-07-23 08:24 AM
Hi Rachael,
There are lot many ways to replace the leading zeros. But I would suggest the best way to remove leading zeros in excel it self.
You can convert the the excel to general or number format it will remove leading zeros.
2nd way you can copy that columns and paste as values in another column then leading zeros will go away. Then you take it to collection.
12-07-23 09:15 AM
Thanks Michael , I have tried this and it works prefectly.