11 Replies Latest reply on Mar 6, 2007 3:54 PM by Newsgroup_User

    restrict length of string

    Level 7
      I am pulling headlines from a database table to create a drop down list.
      Some of the headlines are very long and therefore outputting the entire
      headline makes my drop down too long for the table.

      I am trying to use Len and Left, but its not working. Some help with what I
      am doing wrong would be great.

      Thanks,
      Kim


      <cfoutput query="rsGetNewsInfo">
      <cfif #Len(rsGetNewsInfo.NewsHeadline)# GT 35>
      <cfset NewsHeadline = Left(rsGetNewsInfo.NewsHeadline, 20)>
      <cfelse>
      <cfset NewsHeadline = #rsGetNewsInfo.NewsHeadline#>
      </cfif>
      <option
      value="#rsGetNewsInfo.NewsID#">#DateFormat(rsGetNewsInfo.PostDate,
      'm/d/yy')# - #NewsHeadline#</option>
      </cfoutput>


        • 1. Re: restrict length of string
          Level 7
          <cfoutput query="rsGetNewsInfo">
          <cfif #Len(rsGetNewsInfo.NewsHeadline)# GT 35>
          <cfset NewsHeadline = Left(rsGetNewsInfo.NewsHeadline, 20)>
          <cfelse>
          <cfset NewsHeadline = #rsGetNewsInfo.NewsHeadline#>
          </cfif>
          <option
          value="#rsGetNewsInfo.NewsID#">#DateFormat(rsGetNewsInfo.PostDate,
          'm/d/yy')# - #NewsHeadline#</option>
          </cfoutput>


          Don't work so hard.

          <cfoutput query="rsGetNewsInfo">
          <option
          value="#rsGetNewsInfo.NewsID#">#DateFormat(rsGetNewsInfo.PostDate,
          'm/d/yy')# - #left(rsGetNewsInfo.NewsHeadline, 20)#</option>
          </cfoutput>
          • 2. Re: restrict length of string
            Level 7
            Ian,

            Well, actually, for the shorter headlines, I didn't want to cut them down. I
            want the entire headline to be visible if it's a shorter headline. Its only
            the excessively long ones that need to be cut down. I had set the length to
            35 to see if the code was working, and it wasn't.

            Kim

            "Ian Skinner" <ian.skinner@bloodsource.org> wrote in message
            news:esklag$lul$1@forums.macromedia.com...
            > <cfoutput query="rsGetNewsInfo">
            > <cfif #Len(rsGetNewsInfo.NewsHeadline)# GT 35>
            > <cfset NewsHeadline = Left(rsGetNewsInfo.NewsHeadline, 20)>
            > <cfelse>
            > <cfset NewsHeadline = #rsGetNewsInfo.NewsHeadline#>
            > </cfif>
            > <option
            > value="#rsGetNewsInfo.NewsID#">#DateFormat(rsGetNewsInfo.PostDate,
            > 'm/d/yy')# - #NewsHeadline#</option>
            > </cfoutput>
            >
            >
            > Don't work so hard.
            >
            > <cfoutput query="rsGetNewsInfo">
            > <option
            > value="#rsGetNewsInfo.NewsID#">#DateFormat(rsGetNewsInfo.PostDate,
            > 'm/d/yy')# - #left(rsGetNewsInfo.NewsHeadline, 20)#</option>
            > </cfoutput>


            • 3. Re: restrict length of string
              Level 7
              Ian,

              Well, actually, for the shorter headlines, I didn't want to cut them
              down. I want the entire headline to be visible if it's a shorter
              headline. Its only the excessively long ones that need to be cut down. I
              had set the length to 35 to see if the code was working, and it wasn't.

              Kim


              I'm not sure I understand the requirement here. Left(string,20) will
              show the full string for any string less then or equal to 20 characters.

              Are you saying you want to show up to 35 characters, then cut anything
              longer then 35 to 20 characters?

              • 4. Re: restrict length of string
                Level 7
                I think it could be scope issue. As an FYI you don't the pound signs in the
                if, or set, statements. Try this:

                <cfoutput query="rsGetNewsInfo">
                <cfif Len(rsGetNewsInfo.NewsHeadline) GT 35>
                <cfset Headline = Left(rsGetNewsInfo.NewsHeadline, 20)>
                <cfelse>
                <cfset Headline = rsGetNewsInfo.NewsHeadline>
                </cfif>
                <option
                value="#rsGetNewsInfo.NewsID#">#DateFormat(rsGetNewsInfo.PostDate,
                'm/d/yy')# - #Headline#</option>
                </cfoutput>

                --
                Bryan Ashcraft (remove brain to reply)
                Web Application Developer
                Wright Medical Technology, Inc.
                ------------------------------------------------------------------
                Macromedia Certified Dreamweaver Developer
                Adobe Community Expert (DW) :: http://www.adobe.com/communities/experts/


                "KimMazz" <kimazzNoOil@optonline.net> wrote in message
                news:eskksa$ljp$1@forums.macromedia.com...
                >I am pulling headlines from a database table to create a drop down list.
                >Some of the headlines are very long and therefore outputting the entire
                >headline makes my drop down too long for the table.
                >
                > I am trying to use Len and Left, but its not working. Some help with what
                > I am doing wrong would be great.
                >
                > Thanks,
                > Kim
                >
                >
                > <cfoutput query="rsGetNewsInfo">
                > <cfif #Len(rsGetNewsInfo.NewsHeadline)# GT 35>
                > <cfset NewsHeadline = Left(rsGetNewsInfo.NewsHeadline, 20)>
                > <cfelse>
                > <cfset NewsHeadline = #rsGetNewsInfo.NewsHeadline#>
                > </cfif>
                > <option
                > value="#rsGetNewsInfo.NewsID#">#DateFormat(rsGetNewsInfo.PostDate,
                > 'm/d/yy')# - #NewsHeadline#</option>
                > </cfoutput>
                >
                >


                • 5. Re: restrict length of string
                  Level 7
                  Hi Bryan,

                  I tried it with out the pound signs and it still didn't work. Showed the
                  entire headline. I only put the pound signs in because it didn't work
                  without them, so... when all else fails, add pound signs ;0)


                  Kim

                  "Bash **AdobeCommunityExpert**" <bashcraft@wmtBRAIN.com> wrote in message
                  news:eskn1j$nlo$1@forums.macromedia.com...
                  >I think it could be scope issue. As an FYI you don't the pound signs in the
                  >if, or set, statements. Try this:
                  >
                  > <cfoutput query="rsGetNewsInfo">
                  > <cfif Len(rsGetNewsInfo.NewsHeadline) GT 35>
                  > <cfset Headline = Left(rsGetNewsInfo.NewsHeadline, 20)>
                  > <cfelse>
                  > <cfset Headline = rsGetNewsInfo.NewsHeadline>
                  > </cfif>
                  > <option
                  > value="#rsGetNewsInfo.NewsID#">#DateFormat(rsGetNewsInfo.PostDate,
                  > 'm/d/yy')# - #Headline#</option>
                  > </cfoutput>
                  >
                  > --
                  > Bryan Ashcraft (remove brain to reply)
                  > Web Application Developer
                  > Wright Medical Technology, Inc.
                  > ------------------------------------------------------------------
                  > Macromedia Certified Dreamweaver Developer
                  > Adobe Community Expert (DW) :: http://www.adobe.com/communities/experts/
                  >
                  >
                  > "KimMazz" <kimazzNoOil@optonline.net> wrote in message
                  > news:eskksa$ljp$1@forums.macromedia.com...
                  >>I am pulling headlines from a database table to create a drop down list.
                  >>Some of the headlines are very long and therefore outputting the entire
                  >>headline makes my drop down too long for the table.
                  >>
                  >> I am trying to use Len and Left, but its not working. Some help with what
                  >> I am doing wrong would be great.
                  >>
                  >> Thanks,
                  >> Kim
                  >>
                  >>
                  >> <cfoutput query="rsGetNewsInfo">
                  >> <cfif #Len(rsGetNewsInfo.NewsHeadline)# GT 35>
                  >> <cfset NewsHeadline = Left(rsGetNewsInfo.NewsHeadline, 20)>
                  >> <cfelse>
                  >> <cfset NewsHeadline = #rsGetNewsInfo.NewsHeadline#>
                  >> </cfif>
                  >> <option
                  >> value="#rsGetNewsInfo.NewsID#">#DateFormat(rsGetNewsInfo.PostDate,
                  >> 'm/d/yy')# - #NewsHeadline#</option>
                  >> </cfoutput>
                  >>
                  >>
                  >
                  >


                  • 6. Re: restrict length of string
                    Level 7
                    Ian,

                    Some headlines may be 10 characters, some 30 characters, some 50 characters,
                    and some 125 characters, If its over a certain length, say 75 characters I
                    want it cut down. But for the headlines that are shorter, say 73 characters
                    I want it to show the entire headline. So, I thought I needed to test for
                    the length first and then fix it from there.

                    But, your suggestion works, I'll just allow a longer length for the count.

                    Kim
                    "Ian Skinner" <ian.skinner@bloodsource.org> wrote in message
                    news:eskm7b$mnl$1@forums.macromedia.com...
                    > Ian,
                    >
                    > Well, actually, for the shorter headlines, I didn't want to cut them down.
                    > I want the entire headline to be visible if it's a shorter headline. Its
                    > only the excessively long ones that need to be cut down. I had set the
                    > length to 35 to see if the code was working, and it wasn't.
                    >
                    > Kim
                    >
                    >
                    > I'm not sure I understand the requirement here. Left(string,20) will show
                    > the full string for any string less then or equal to 20 characters.
                    >
                    > Are you saying you want to show up to 35 characters, then cut anything
                    > longer then 35 to 20 characters?
                    >


                    • 7. Re: restrict length of string
                      Level 7
                      The pound signs were just a side note. Look at the name of the variable in
                      the cfset statement. You had it named the same as the query column which
                      could be causing a scope issue. I changed the name.

                      --
                      Bryan Ashcraft (remove brain to reply)
                      Web Application Developer
                      Wright Medical Technology, Inc.
                      ------------------------------------------------------------------
                      Macromedia Certified Dreamweaver Developer
                      Adobe Community Expert (DW) :: http://www.adobe.com/communities/experts/


                      "KimMazz" <kimazzNoOil@optonline.net> wrote in message
                      news:esknto$ohu$1@forums.macromedia.com...
                      > Hi Bryan,
                      >
                      > I tried it with out the pound signs and it still didn't work. Showed the
                      > entire headline. I only put the pound signs in because it didn't work
                      > without them, so... when all else fails, add pound signs ;0)
                      >
                      >
                      > Kim
                      >
                      > "Bash **AdobeCommunityExpert**" <bashcraft@wmtBRAIN.com> wrote in message
                      > news:eskn1j$nlo$1@forums.macromedia.com...
                      >>I think it could be scope issue. As an FYI you don't the pound signs in
                      >>the if, or set, statements. Try this:
                      >>
                      >> <cfoutput query="rsGetNewsInfo">
                      >> <cfif Len(rsGetNewsInfo.NewsHeadline) GT 35>
                      >> <cfset Headline = Left(rsGetNewsInfo.NewsHeadline, 20)>
                      >> <cfelse>
                      >> <cfset Headline = rsGetNewsInfo.NewsHeadline>
                      >> </cfif>
                      >> <option
                      >> value="#rsGetNewsInfo.NewsID#">#DateFormat(rsGetNewsInfo.PostDate,
                      >> 'm/d/yy')# - #Headline#</option>
                      >> </cfoutput>
                      >>
                      >> --
                      >> Bryan Ashcraft (remove brain to reply)
                      >> Web Application Developer
                      >> Wright Medical Technology, Inc.
                      >> ------------------------------------------------------------------
                      >> Macromedia Certified Dreamweaver Developer
                      >> Adobe Community Expert (DW) :: http://www.adobe.com/communities/experts/
                      >>
                      >>
                      >> "KimMazz" <kimazzNoOil@optonline.net> wrote in message
                      >> news:eskksa$ljp$1@forums.macromedia.com...
                      >>>I am pulling headlines from a database table to create a drop down list.
                      >>>Some of the headlines are very long and therefore outputting the entire
                      >>>headline makes my drop down too long for the table.
                      >>>
                      >>> I am trying to use Len and Left, but its not working. Some help with
                      >>> what I am doing wrong would be great.
                      >>>
                      >>> Thanks,
                      >>> Kim
                      >>>
                      >>>
                      >>> <cfoutput query="rsGetNewsInfo">
                      >>> <cfif #Len(rsGetNewsInfo.NewsHeadline)# GT 35>
                      >>> <cfset NewsHeadline = Left(rsGetNewsInfo.NewsHeadline, 20)>
                      >>> <cfelse>
                      >>> <cfset NewsHeadline = #rsGetNewsInfo.NewsHeadline#>
                      >>> </cfif>
                      >>> <option
                      >>> value="#rsGetNewsInfo.NewsID#">#DateFormat(rsGetNewsInfo.PostDate,
                      >>> 'm/d/yy')# - #NewsHeadline#</option>
                      >>> </cfoutput>
                      >>>
                      >>>
                      >>
                      >>
                      >
                      >


                      • 8. Re: restrict length of string
                        Level 7
                        <cfoutput query="rsGetNewsInfo">
                        <cfif #Len(rsGetNewsInfo.NewsHeadline)# GT 35>
                        <cfset NewsHeadline = Left(rsGetNewsInfo.NewsHeadline, 20)>
                        <cfelse>
                        <cfset NewsHeadline = #rsGetNewsInfo.NewsHeadline#>
                        </cfif>
                        <option
                        value="#rsGetNewsInfo.NewsID#">#DateFormat(rsGetNewsInfo.PostDate,
                        'm/d/yy')# - #NewsHeadline#</option>
                        </cfoutput>


                        For edification purposes on why this original code did not work as
                        expected. By running this code you now have two variables named
                        'NewsHeadline'. The original in the 'rsGetNewsInfo' query scope, and a
                        new one in the local 'variables' scope. The former is the one CF was
                        picking to display in your output statement.

                        A Small Experiment.

                        <cfoutput query="rsGetNewsInfo">
                        <cfif Len(rsGetNewsInfo.NewsHeadline) GT 35>
                        <cfset NewsHeadline = Left(rsGetNewsInfo.NewsHeadline, 20)>
                        <cfelse>
                        <cfset NewsHeadline = rsGetNewsInfo.NewsHeadline>
                        </cfif>
                        <option
                        value="#rsGetNewsInfo.NewsID#">#DateFormat(rsGetNewsInfo.PostDate,
                        'm/d/yy')# - #rsGetNewsInfo.NewsHeadline#:#variables.NewsHeadline#</option>
                        </cfoutput>
                        • 9. Re: restrict length of string
                          Level 7
                          That's what I was trying to say. ;^)

                          --
                          Bryan Ashcraft (remove brain to reply)
                          Web Application Developer
                          Wright Medical Technology, Inc.
                          ------------------------------------------------------------------
                          Macromedia Certified Dreamweaver Developer
                          Adobe Community Expert (DW) :: http://www.adobe.com/communities/experts/


                          "Ian Skinner" <ian.skinner@bloodsource.org> wrote in message
                          news:eskr1j$re1$1@forums.macromedia.com...
                          > <cfoutput query="rsGetNewsInfo">
                          > <cfif #Len(rsGetNewsInfo.NewsHeadline)# GT 35>
                          > <cfset NewsHeadline = Left(rsGetNewsInfo.NewsHeadline, 20)>
                          > <cfelse>
                          > <cfset NewsHeadline = #rsGetNewsInfo.NewsHeadline#>
                          > </cfif>
                          > <option
                          > value="#rsGetNewsInfo.NewsID#">#DateFormat(rsGetNewsInfo.PostDate,
                          > 'm/d/yy')# - #NewsHeadline#</option>
                          > </cfoutput>
                          >
                          >
                          > For edification purposes on why this original code did not work as
                          > expected. By running this code you now have two variables named
                          > 'NewsHeadline'. The original in the 'rsGetNewsInfo' query scope, and a
                          > new one in the local 'variables' scope. The former is the one CF was
                          > picking to display in your output statement.
                          >
                          > A Small Experiment.
                          >
                          > <cfoutput query="rsGetNewsInfo">
                          > <cfif Len(rsGetNewsInfo.NewsHeadline) GT 35>
                          > <cfset NewsHeadline = Left(rsGetNewsInfo.NewsHeadline, 20)>
                          > <cfelse>
                          > <cfset NewsHeadline = rsGetNewsInfo.NewsHeadline>
                          > </cfif>
                          > <option
                          > value="#rsGetNewsInfo.NewsID#">#DateFormat(rsGetNewsInfo.PostDate,
                          > 'm/d/yy')# -
                          > #rsGetNewsInfo.NewsHeadline#:#variables.NewsHeadline#</option>
                          > </cfoutput>


                          • 10. Re: restrict length of string
                            Level 7
                            Bryan,

                            I didn't realize you had changed the code I posted. I read through so fast I
                            didn't see that. Thanks for giving me the answer and the explanation.

                            Kim

                            "Bash **AdobeCommunityExpert**" <bashcraft@wmtBRAIN.com> wrote in message
                            news:eskqih$r15$1@forums.macromedia.com...
                            > The pound signs were just a side note. Look at the name of the variable in
                            > the cfset statement. You had it named the same as the query column which
                            > could be causing a scope issue. I changed the name.
                            >
                            > --
                            > Bryan Ashcraft (remove brain to reply)
                            > Web Application Developer
                            > Wright Medical Technology, Inc.
                            > ------------------------------------------------------------------
                            > Macromedia Certified Dreamweaver Developer
                            > Adobe Community Expert (DW) :: http://www.adobe.com/communities/experts/
                            >
                            >
                            > "KimMazz" <kimazzNoOil@optonline.net> wrote in message
                            > news:esknto$ohu$1@forums.macromedia.com...
                            >> Hi Bryan,
                            >>
                            >> I tried it with out the pound signs and it still didn't work. Showed the
                            >> entire headline. I only put the pound signs in because it didn't work
                            >> without them, so... when all else fails, add pound signs ;0)
                            >>
                            >>
                            >> Kim
                            >>
                            >> "Bash **AdobeCommunityExpert**" <bashcraft@wmtBRAIN.com> wrote in message
                            >> news:eskn1j$nlo$1@forums.macromedia.com...
                            >>>I think it could be scope issue. As an FYI you don't the pound signs in
                            >>>the if, or set, statements. Try this:
                            >>>
                            >>> <cfoutput query="rsGetNewsInfo">
                            >>> <cfif Len(rsGetNewsInfo.NewsHeadline) GT 35>
                            >>> <cfset Headline = Left(rsGetNewsInfo.NewsHeadline, 20)>
                            >>> <cfelse>
                            >>> <cfset Headline = rsGetNewsInfo.NewsHeadline>
                            >>> </cfif>
                            >>> <option
                            >>> value="#rsGetNewsInfo.NewsID#">#DateFormat(rsGetNewsInfo.PostDate,
                            >>> 'm/d/yy')# - #Headline#</option>
                            >>> </cfoutput>
                            >>>
                            >>> --
                            >>> Bryan Ashcraft (remove brain to reply)
                            >>> Web Application Developer
                            >>> Wright Medical Technology, Inc.
                            >>> ------------------------------------------------------------------
                            >>> Macromedia Certified Dreamweaver Developer
                            >>> Adobe Community Expert (DW) :: http://www.adobe.com/communities/experts/
                            >>>
                            >>>
                            >>> "KimMazz" <kimazzNoOil@optonline.net> wrote in message
                            >>> news:eskksa$ljp$1@forums.macromedia.com...
                            >>>>I am pulling headlines from a database table to create a drop down list.
                            >>>>Some of the headlines are very long and therefore outputting the entire
                            >>>>headline makes my drop down too long for the table.
                            >>>>
                            >>>> I am trying to use Len and Left, but its not working. Some help with
                            >>>> what I am doing wrong would be great.
                            >>>>
                            >>>> Thanks,
                            >>>> Kim
                            >>>>
                            >>>>
                            >>>> <cfoutput query="rsGetNewsInfo">
                            >>>> <cfif #Len(rsGetNewsInfo.NewsHeadline)# GT 35>
                            >>>> <cfset NewsHeadline = Left(rsGetNewsInfo.NewsHeadline, 20)>
                            >>>> <cfelse>
                            >>>> <cfset NewsHeadline = #rsGetNewsInfo.NewsHeadline#>
                            >>>> </cfif>
                            >>>> <option
                            >>>> value="#rsGetNewsInfo.NewsID#">#DateFormat(rsGetNewsInfo.PostDate,
                            >>>> 'm/d/yy')# - #NewsHeadline#</option>
                            >>>> </cfoutput>
                            >>>>
                            >>>>
                            >>>
                            >>>
                            >>
                            >>
                            >
                            >


                            • 11. Re: restrict length of string
                              Level 7
                              Ian,

                              Thanks for telling me this. By telling me why it doesn't work it actually
                              helps me to understand and also allows me the opportunity to code it
                              correctly the next time around.

                              Greatly appreciated.

                              Kim

                              "Ian Skinner" <ian.skinner@bloodsource.org> wrote in message
                              news:eskr1j$re1$1@forums.macromedia.com...
                              > <cfoutput query="rsGetNewsInfo">
                              > <cfif #Len(rsGetNewsInfo.NewsHeadline)# GT 35>
                              > <cfset NewsHeadline = Left(rsGetNewsInfo.NewsHeadline, 20)>
                              > <cfelse>
                              > <cfset NewsHeadline = #rsGetNewsInfo.NewsHeadline#>
                              > </cfif>
                              > <option
                              > value="#rsGetNewsInfo.NewsID#">#DateFormat(rsGetNewsInfo.PostDate,
                              > 'm/d/yy')# - #NewsHeadline#</option>
                              > </cfoutput>
                              >
                              >
                              > For edification purposes on why this original code did not work as
                              > expected. By running this code you now have two variables named
                              > 'NewsHeadline'. The original in the 'rsGetNewsInfo' query scope, and a
                              > new one in the local 'variables' scope. The former is the one CF was
                              > picking to display in your output statement.
                              >
                              > A Small Experiment.
                              >
                              > <cfoutput query="rsGetNewsInfo">
                              > <cfif Len(rsGetNewsInfo.NewsHeadline) GT 35>
                              > <cfset NewsHeadline = Left(rsGetNewsInfo.NewsHeadline, 20)>
                              > <cfelse>
                              > <cfset NewsHeadline = rsGetNewsInfo.NewsHeadline>
                              > </cfif>
                              > <option
                              > value="#rsGetNewsInfo.NewsID#">#DateFormat(rsGetNewsInfo.PostDate,
                              > 'm/d/yy')# -
                              > #rsGetNewsInfo.NewsHeadline#:#variables.NewsHeadline#</option>
                              > </cfoutput>