Help - Search - Members - Calendar
Full Version: Escaping Comma
W3Schools Forum > Server Scripting > ColdFusion
vchris
I have a list and one of my list entries has a comma. How do I escape a comma in a list?

Example of the entry:
<cfset sectorList = ListAppend(sectorList, "iron,_steel_and_limenite_smelting") />
Skemcin
CODE
<cfset sectorList = ListAppend(sectorList, "iron#chr(44)#_steel_and_limenite_smelting") />


That should do it.

Use this code to get the numeric value of the chr() function you are looking for:
CODE
<cfloop index="x" from="1" to="50">
<cfoutput>
#x# = #Chr(x)#<br />
</cfoutput>
</cfloop>


Increase the "to" value here to something like 5000 or 50000 to get even more characters.
xd.gif
Skemcin
As I think about it more, that might not work either . . . I'd have to look into this a little more if it doesn't.

Are you able to replace it with some other value that you could then translate whenever this information is retrieved again?
vchris
Yeah I just tried it out and it doesn't work.

See for yourself:
<cfset myList = "john#chr(44)# test" />
<cfloop index="i" list="#myList#">
<cfoutput>#i#</cfoutput>
</cfloop>

Could I change the default delimiter to something else?

EDIT:
I got it! I replaced the default delimiter by a !. It works perfectly.
vchris
oh oh got another problem.

See I have this drop down that is populated with this coldfusion list I created. Then when a selection is made a list of links appears underneath the drop down that the user can click on to go view a certain document.

So I have:
<cfset sectorList = ListAppend(sectorList, "iron,_steel_and_limenite_smelting","!") />

<cfset iron,_steel_and_limenite_smelting = '<a href="##">link 1</a>,<a href="##">link 2</a>' />

but the comma is not accepted in a variable name. Basically I have the drop down option value equal to the coldfusion variable. All the option in my drop down have a list of their own links. I'm not sure if this is the best way to do this but I thought it was simpler than arrays and easier to update. If you have a better way of doing this let me know.
Skemcin
Could you use the position in the array as the value instead of the actual value of the array item?
vchris
These are lists not arrays.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.