2

I need to pull out (parse) the middle section of a data record, the typical record is similar to this string:

CARY 12345 (Supporting documentation here).

What I need to do is pull out just the 12345 portion of the data record. I've been using this CF code:

cnumber = '00' & listFirst( listLast( ctic, ' ' ), ' ' );

But the results output like this:

00(Supporting documentation here).

Instead, I would like the output to be:

0012345
Leigh
  • 28,765
  • 10
  • 55
  • 103

2 Answers2

4

If you're certain that your data would always look like that, and you always want to get the second item, you could do something like:

listGetAt(myData,2," ")

To pad with zeroes, you can use numberFormat():

numberFormat(listGetAt(myData,2," "),"0000000")

but this makes a number of assumptions about the format of your data and will break down if it doesn't match.

Fish Below the Ice
  • 1,273
  • 13
  • 23
  • Actually your initial comment worked: I think you were looking for listRest() rather than listLast(). The actual code: cnumber = listFirst( listRest( cTic, ' ' ), ' ' ); – Cajun WebDev Jan 29 '15 at 21:13
2

Try Mid and Replace together

    <cfoutput>
       <cfset str = Mid("CARY 12345","5", "6")>
       <cfset str = "00"&str>
       <cfset str = Replace(str, " ","","All")>
           #str#
     </cfoutput>
Ronnie Kumar
  • 635
  • 5
  • 18