Skip to main content
Known Participant
February 5, 2010
Answered

Find the number of occurances in string, to break up output

  • February 5, 2010
  • 1 reply
  • 506 views

I have a string that might contain 12345, or 12335,6789, or 123435,6789,9999, etc...unlimited

When I display, the string is very long, lengthwise. So I want to break it up and display one on top of another.

I started to use the Find function to location the postion of the comma, then used Mid function to get the first value, the repeat similar process to get the second and third values. This seems to work and the display is the way I want it.

Howver, I know I have three values inside the string, so I can adjust accordinly. What if I do not know how many values there are ? How would I separate to get the desired output ?

This is my code so far, based on three values :

<cfset pos1 = Find(",","#qry.carrierTracking#")>

<cfif pos1 is not 0>
<cfset carrier1 = #mid(qry.carrierTracking,1,(pos1 - 1))#>
<cfset carrier2 = #mid(qry.carrierTracking,(pos1 + 1),50)#>
</cfif>

<cfset pos2 = Find(",","#carrier2#")>

<cfif pos2 is not 0>
<cfset carrier2A = #mid(carrier2,1,(pos2 - 1))#>
<cfset carrier3 = #mid(carrier2,(pos2 + 1),50)#>
</cfif>


<cfif pos1 is not 0 and pos2 is not 0>
<cfoutput>#carrier1#<br>#carrier2A#<br>#carrier3#<br></cfoutput>
</cfif>

This topic has been closed for replies.
Correct answer BKBK

<cfset carrierTracking = replace(qry.carrierTracking, ",", "<br>", "all")>


<cfoutput>#carrierTracking#</cfoutput>

1 reply

Inspiring
February 5, 2010

Treat your string as a list.

Known Participant
February 6, 2010

ok, If it is treated as a string, how can I display the output with a line break after each comma ?

Inspiring
February 6, 2010

Wouldn't you just replace all the commas with a comma followed by a <br /> ?


--

Adam