Skip to main content
Answer

Padding Text to a fixed length

  • December 1, 2023
  • 2 replies
  • 290 views

Forum|alt.badge.img+10

Is there a way to pad text in order to make it a fixed length? For instance, I have a string of numbers that can be anywhere from one to five characters. If the string only has one character, I would like to add four zeros to the left of the string for a total length of five characters.  I'm new to this platform so any assistance is greatly appreciated. 

Best answer by arjun.meda

Yes, absolutely. Here are the steps to pad text to make it to a fixed length.

  1. Get the length of the string using the action: String → Length
  2. Loop while the length of the string is less than 5.
  3. Add 0 to your string using the action String → Assign
  4. Get the length of the string again (within the loop) to check if it has reached 5 in the next iteration.

Attached a sample automation for your reference.

Hope this helps, let me know.

2 replies

arjun.meda
Automation Anywhere Team
Forum|alt.badge.img+14
  • Automation Anywhere Team
  • Answer
  • December 4, 2023

Yes, absolutely. Here are the steps to pad text to make it to a fixed length.

  1. Get the length of the string using the action: String → Length
  2. Loop while the length of the string is less than 5.
  3. Add 0 to your string using the action String → Assign
  4. Get the length of the string again (within the loop) to check if it has reached 5 in the next iteration.

Attached a sample automation for your reference.

Hope this helps, let me know.


Forum|alt.badge.img+10
  • Author
  • Cadet | Tier 2
  • December 4, 2023

Thank you very much Arjun! I was hoping there might be an action for this. I appreciate your help.