Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Feb 05, 2010 Feb 05, 2010

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>

TOPICS
Getting started
454
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 07, 2010 Feb 07, 2010

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


<cfoutput>#carrierTracking#</cfoutput>
Translate
LEGEND ,
Feb 05, 2010 Feb 05, 2010

Treat your string as a list.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 05, 2010 Feb 05, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 05, 2010 Feb 05, 2010

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


--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 07, 2010 Feb 07, 2010
LATEST

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


<cfoutput>#carrierTracking#</cfoutput>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources