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

Remove item from ValueList?

Explorer ,
Nov 26, 2008 Nov 26, 2008
From a query I am creating a list using quotedValueList. There will be a need for me to remove an item or two from the list. When I currently do it, I'm left with single quotes and the comma. I want to have a clean list b/c i will eventually be passing the list into an SQL statement.

This is what I have.

<CFSET test=#QuotedValueList(getPerson.id,",")#>

Test : '1231','1232','1233'

#Replace(variables.test, '1232', "", "all")#

Test : '1231','','1233'
927
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

Explorer , Nov 26, 2008 Nov 26, 2008
<CFSET test=#QuotedValueList(getPerson.id,",")#>
first string: #test#<BR>
<CFSET deletePosition=#listfind(variables.test,"'1232'")#>
delete: #deletePosition#
<CFSET test=#listDeleteAt(variables.test,variables.deletePosition)#>
#variables.test#
Translate
Explorer ,
Nov 26, 2008 Nov 26, 2008
<CFSET test=#QuotedValueList(getPerson.id,",")#>
first string: #test#<BR>
<CFSET deletePosition=#listfind(variables.test,"'1232'")#>
delete: #deletePosition#
<CFSET test=#listDeleteAt(variables.test,variables.deletePosition)#>
#variables.test#
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 ,
Nov 26, 2008 Nov 26, 2008
Then you need to also replace the quotes, not just the characters
between them

#Replace(variables.test,"'12321'","","all")#
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 ,
Nov 26, 2008 Nov 26, 2008
Ways to improve on the existing answer.

1. If possible, strengthen the where clause of your first query so the value list has only the items you want.
2. In the 2nd query, use cfqueryparam list="yes". Then you can use a normal value list and not have to worry about quotes.
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
Guest
Nov 30, 2008 Nov 30, 2008
LATEST
Folks, too many people make use #xxxxx# when it's totally unnecessary, it's inefficient and it's harder to read.

THIS

<CFSET test=QuotedValueList(getPerson.id,",")>
<CFSET deletePosition=listfind(variables.test,"'1232'")>
<CFSET test=listDeleteAt(variables.test,variables.deletePosition)>

NOT

<CFSET test=#QuotedValueList(getPerson.id,",")#>
<CFSET deletePosition=#listfind(variables.test,"'1232'")#>
<CFSET test=#listDeleteAt(variables.test,variables.deletePosition)#>

General rule, if you're not displaying it you probably don't need ##. If you aren't displaying it but it's inside quotes then you probably need it
e.g. <CFSET firstlast = "#RTrim(firstname)# #RTrim(lastname)#">
although an alternative is
<CFSET firstlast = Trim(firstname) & " " & Trim(lastname)>
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