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

Question

Question

Feature Request: Function to add a space onto a token if it is not empty.

asked on July 16, 2015

One common issue aesthetic issue when naming folders is how to account for optional tokens. 

 

For example, say I have a folder I'm naming Last, First Middle Suffix. 

 

I have three people:

Jones, Bob Jr

Jones, Bobby Ray Jr

Jones, Bobby

 

These three will rename a folder 

Jones, Bob  Jr  (two spaces)

Jones, Bobby Ray Jr

Jones, Bobby (with a trailing space that LF drops automatically)

 

 

To take care of that extra space on the first example, I need to go through a series of conditionals to create a token (or a separate rename function) to name it without that space.

 

I'm wondering if we might be able to add a function into the Token Builder that would allow us to format an existing token with a trailing space (any char would be even better) only if the token is not empty. 

 

0 0

Answer

SELECTED ANSWER
replied on July 16, 2015

%(Token 1#@Split( );RemoveEmptyItems@##[ ]#) seems to do it for me: split on the space, remove the extra empty item that gets generated in between the 2 consecutive spaces, flatten it back into a single value with single space as delimiters.

2 0
replied on July 16, 2015

So I'd create one token with all pieces inside it, then sub that token in place of Token 1, right? (not in a place I can test this atm)

 

0 0
replied on July 16, 2015

Yes.

0 0

Replies

replied on July 16, 2015 Show version history

Chris - How about using the Script activity 'hammer'? smiley

        Protected Overrides Sub Execute()
            Dim firstName As String = Me.GetTokenValue("RetrieveFieldValues_First Name")
            Dim lastName As String = Me.GetTokenValue("RetrieveFieldValues_Last Name")
            Dim midleName As String = Me.GetTokenValue("RetrieveFieldValues_Middle Name")
            Dim suffix As String = Me.GetTokenValue("RetrieveFieldValues_Suffix")
            Dim fullName As String = ""

            If String.IsNullOrEmpty(lastName) Then

                Me.WorkflowApi.TrackError("Last name field cannot be empty.")

            Else

                fullName = lastName & ","

                If Not String.IsNullOrEmpty(firstName) Then fullName &= " " & firstName
                If Not String.IsNullOrEmpty(midleName) Then fullName &= " " & midleName
                If Not String.IsNullOrEmpty(suffix) Then fullName &= " " & suffix

            End If

            Me.SetTokenValue("FullName", fullName)

        End Sub

You could do the string concatenation on a single line with the inline 'IIf' but it would be hard to read...

 

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

Sign in to reply to this post.