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

Question

Question

fixed length string

asked on May 6, 2022

I am writing a series of tokens to text box.  I want the text to be columized.  How can I use token formating or regular expressions to make each token a fixed length to get the text in columns.

0 0

Replies

replied on May 6, 2022

Are you trying to display text in a table-like way within a textbox? If so, that's going to present a challenge because character pixel widths are inconsistent.

For example, each of the following is 10 characters (5 letters, 5 whitespace) but the visible "length" varies significantly.

TESTA     |

TestB    |

TESTW     |

0 0
replied on May 6, 2022

Brian, I think your best option is to use a Script Activity.

        Protected Overrides Sub Execute()
            'Write your code here.

            Dim sPhrase As String = GetTokenValue("StringToPad")
            Dim sLen As String = GetTokenValue("OutputLength")
            Dim iLen As Integer
            If Integer.TryParse(sLen,iLen) Then
                If sPhrase.Length < iLen Then
                    SetTokenValue("PaddedPhrase", sPhrase.PadRight(iLen))
                Else
                    ' To return truncated to iLen
                    SetTokenValue("PaddedPhrase", sPhrase.Substring(0, iLen))
                    ' To return whole string
                    ' SetTokenValue("PaddedPhrase",sPhrase)
                End If
            End If
        End Sub

 

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

Sign in to reply to this post.