Skip to main content
Inspiring
February 18, 2009
Question

String Manipulation??

  • February 18, 2009
  • 3 replies
  • 348 views
Hi,

I am using CF8. I knew how to do this before, but can't recall now.

How I can extract the all the numbers to the left of the "_" (underscore)? The length to the left might be 3 or more

Sample data:

522_1 (in this case, grab just the 522)
92223_5 (in this case, grab just the 92223).

Hope that makes sense.

-Westside
    This topic has been closed for replies.

    3 replies

    Participating Frequently
    February 18, 2009
    <cfset theFirstChunk = ListFirst("522_1","_")>
    Inspiring
    February 18, 2009
    ListFirst
    Inspiring
    February 18, 2009
    WestSide wrote:
    > Hi,
    >
    > I am trying to find out how to loop over a query horizontally in a sense. My
    > recordset looks like this:
    >
    > Column Headers (each number represents a question_id, and the email column is
    > the user's email address )
    > 1 | 2 | 3 | 4 | 5 | 6 |7 | 8 | 9 | 10 | 11 | 12 | Email
    >
    > Sample Values
    > 3 | 5 | 3 | 5 | 5 | 4 | 3 | 2 | 5 | 5 | 4 | 1 | johndoe@test.com
    >
    > 4 | 4 | 2 | 4 | 5 | 2 | 1 | 2 | 5 | 3 | 4 | 2 | roger@abccompany.com
    >
    > --------------
    >
    > Each row represents multiple answers to multiple questions. So for a given
    > row I need to grab the header which is the question_id, then grab the
    > associated value and insert it into the database. So I really need to loop
    > over each column within the row.

    <cfloop from="1" to="#answers.recordCount#" index="i">

    <cfloop from="1" to="#ListLen(answers.ColumnList)#" index="j">
    QuestionID=#ListGetAt(answers.ColumnList, j)#
    Answer=#answers[ListGetAt(answers.ColumnList, j)] #
    </cfloop>
    </cfloop>

    --
    Mack