Skip to main content
November 6, 2009
Question

String Length

  • November 6, 2009
  • 1 reply
  • 500 views

I have a query that get 3 fields I put the fields together using a query of query and do this:

<cfset myField = # Field1#  #Fields2#  #Fileds3#>

This works ok....

Field1 has a data that is always 9 char thats perfect so the Field2 has a space between Field1 and Field2 that is consistent.

Field 2 can be anywhere from 1 to 36 char, this means that the Field3 does not line up to the one above it. How can I force the Field2 to always be 36 char even though the data varies in length. This is causing the Field3 to not line up.

I have tried:

LJustify, looping and setting it with " "

not sure what else to try any thoughts?

this is what I get now:

90002345    testdata     this is the long description

90002346    testdata...2     this is the long description

90002347    testdata.......4     this is the long description

90002348    testdata....5     this is the long description

This is what I want:

90002345    testdata          this is the long description

90002346    testdata...2     this is the long description

90002347    testdata......4  this is the long description

90002348    testdata....5    this is the long description

Thanks

George

    This topic has been closed for replies.

    1 reply

    Inspiring
    November 7, 2009

    Your36CharacterString = Left(YourString & "                                   ", 36);

    Inspiring
    November 7, 2009

    Your36CharacterString = Left(YourString & "                                   ", 36);

    Whilst that'll work, that's a bit leaden, Dan.

    One can just add the correct number of space characters from the outset by using repeatString(" ", 36-len(originalString)).

    I guess for robustness, a check should be made that the original string is not already at least 36 chars.  Dan's solution doesn't need this consideration.

    --

    Adam

    BKBK
    Community Expert
    Community Expert
    November 7, 2009

    Your36CharacterString = Left(YourString & "                                   ", 36);

    Whilst that'll work, that's a bit leaden, Dan.

    One can just add the correct number of space characters from the outset by using repeatString(" ", 36-len(originalString)).

    I guess for robustness, a check should be made that the original string is not already at least 36 chars.  Dan's solution doesn't need this consideration.

    I second Dan's answer. If there is one answer that is leaden, it is yours, Adam. It has one more function call and, by your own admission, comes short on robustness.