|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
HELP! Simple Find Function gone mad!
Here is my code:
<CFSET SectionTitle = ArrayNew(1)> <CFSET SectionTitle[1] = "Bob"> <CFSET SectionTitle[2] = "Elaine"> <CFSET SectionTitle[3] = "Simon"> <CFSET SectionTitle[4] = "Peter"> <CFSET SectionTitle[5] = "Ann"> <CFSET SectionTitle[6] = "Jack"> <CFSET SectionTitle[7] = "John"> <html> <head> <!---Section detector---> <CFPARAM name="Mysection" default=""> <!---Section detector, end---> <cfset VarTitle="John"> <cfif isDefined("VarTitle")> <cfoutput><title>#VarTitle#</title></cfoutput> </cfif> <CFLOOP from="1" to="#ArrayLen(Mysection)#" index="APos"> #Find(SectionTitle[APos],VarTitle)# <CFIF SectionTitle[APos] IS TRUE> <CFSET Mysection=VarTitle> <CFELSE> <CFSET Mysection="ERROR"> </CFIF> </CFLOOP> </head> <body> <cfoutput>#Mysection#</cfoutput> </body> </html> And this is what I get on the Browser: #Find(#SectionTitle[APos]#,#VarTitle#)# #Find(#SectionTitle[APos]#,#VarTitle#)# #Find(#SectionTitle[APos]#,#VarTitle#)# #Find(#SectionTitle[APos]#,#VarTitle#)# #Find(#SectionTitle[APos]#,#VarTitle#)# #Find(#SectionTitle[APos]#,#VarTitle#)# #Find(#SectionTitle[APos]#,#VarTitle#)# ERROR Why?, could anyone please enlighten my sorry self? |
|
#2
|
|||
|
|||
|
The problem is the way you are using the Find function. You can't just use find inside a variable to do what you want. It needs to be used inside a statement. This should work:
<CFLOOP from="1" to="#ArrayLen(Mysection)#" index="APos"> <CFIF FindNoCase(SectionTitle[APos], VarTitle) IS TRUE> <CFSET Mysection=VarTitle> <CFELSE> <CFSET Mysection="ERROR"> </CFIF> </CFLOOP> |
|
#3
|
|||
|
|||
|
It works!
It works perfectly mate! Thanks a lot!!
I'll know that next time, do you always have to keep your script within CF tags in Cold Fusion or is there an alternative? Cheers |
|
#4
|
|||
|
|||
|
You CAN use the functions in a variable like this:
<cfoutput> #find( somewords, somemorewords )# </cfoutput> But all that does is return 0 or return the start position of the match, so it's probably not very useful to output that, but rather to use it in some other statement like a conditional. You can also you CFSCRIPT for some of this sort of thing. HTH |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > HELP! Simple Find Function gone mad! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|