You are viewing limited content. For full access, please sign in.

Question

Question

Padding a token value with spaces

asked on March 1, 2018

Hello,

Is it possible in the Token dialog box to apply formatting to a token to pad spaces to the right of the value up to a certain length? For example, suppose I always want a 10-character string and get an input of 'Susie'. Is there a built-in way in workflow to change that into 'Susie     '?

Thanks,

Julie

0 0

Answer

SELECTED ANSWER
replied on March 1, 2018

Hi Julie,

 

My option is to create a temporary token = <value> + 10x<espace>

Exemple : "Susie" + "_ _ _ _ _ _ _ _ _ _" = "Susie_ _ _ _ _ _ _ _ _ _" (15 characters)

Then, just pick the first 10 characters on the left => "Susie_ _ _ _ _" (10 characters)

 

Like that, you can be sure you will always have at least 10 characters.

 

 

Step 1 : Create a token Name

Step 2 : Create a token Temp = token name + 10 spaces

Step 3 : Use pattern matching to get the first 10 caracters

(For the example, I replaced blank space by "_" to show you the result)

0 0
replied on March 2, 2018

Thanks Oliver. That's a good approach. Although now I am thinking it may just be  more efficient if I do it in SQL in the where clause (adding spaces and just taking the leftmost 10 characters).

0 0

Replies

replied on March 2, 2018 Show version history

You can use the token calculator to pad a string value.   To pad the token 'Name' to 10 characters with spaces:  %(Name)&REPT(" ", (10-LEN(%(Name)) ))

This will result in an error if the length of the string is greater than 10 characters, so you would need to check for that.

~ Andrew

Edit:  Had to play with this a little more!

To pad or return the original string if it is greater than 10 characters:
IF((LEN(%(Name))) >= 10, %(Name),%(Name)&REPT(" ", 10 - (IF(LEN(%(Name)) > 10, 0,LEN(%(Name))))))


This will always pad or truncate a string to 10 characters:
IF((LEN(%(Name))) >= 10, LEFT(%(Name),10),%(Name)&REPT(" ", 10 - (IF(LEN(%(Name)) > 10, 0,LEN(%(Name))))))

 

0 0
replied on March 2, 2018

Thanks Andrew. Wish I could mark both as an answer!! 

0 0
replied on August 11, 2020

Sort of on the same line,  is there a good (ie: quick and easy) way to pad characters to the left.   I know we can use the token editor to pad leading zeros, but I have a database that needs to have leading spaces padded.    

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.