coldfusion - Remove duplicates from a list in CF10 -


i have following string before use string, want remove duplicates it:

http://website.com/abc.asp?type=298&action=submit&product=&contribution=&rateterm=&surryr=&mva=&rop=&sortby=1&sortorder=2&pagenum=3&company=&product=&state=&contribution=&rateterm=&surryr=&mva=&rop= 

i tried using cflib function listremoveduplicates, not seem solve issue.

it should like:

http://website.com/abc.asp?type=298&action=submit&product=&contribution=&rateterm=&surryr=&mva=&rop=&sortby=1&sortorder=2&pagenum=3 

i using cf10.

the cfoutput expecting should have company=&state= well. distinct too. taking in account can give try:

<cfset url = "http://website.com/abc.asp?type=298&action=submit&product=&contribution=&rateterm=&surryr=&mva=&rop=&sortby=1&sortorder=2&pagenum=3&company=&product=&state=&contribution=&rateterm=&surryr=&mva=&rop=">  <!--- domain name , query string ---> <cfset domainname = listgetat(url , 1, "?")> <cfset querystring = listgetat(url , 2, "?")> <cfset tempstruct = structnew()> <cfloop list="#querystring#" index="currentstring" delimiters="&">     <cfset tempstruct[ currentstring ] = ""> </cfloop> <cfset querystring = structkeylist(tempstruct,"&")> <cfset newurl = domainname & "?" & querystring> 

output:

http://website.com/abc.asp?rateterm=&company=&mva=&pagenum=3&sortorder=2&product=&rop=&action=submit&state=&type=298&surryr=&contribution=&sortby=1 

and preserve order can define tempstruct this:

<cfset tempstruct = structnew()> <cfset tempstruct = createobject("java", "java.util.linkedhashmap").init() /> 

output:

http://website.com/abc.asp?type=298&action=submit&product=&contribution=&rateterm=&surryr=&mva=&rop=&sortby=1&sortorder=2&pagenum=3&company=&state= 

as using cf10 can use listremoveduplicates this:

<cfset url = "http://website.com/abc.asp?type=298&action=submit&product=&contribution=&rateterm=&surryr=&mva=&rop=&sortby=1&sortorder=2&pagenum=3&company=&product=&state=&contribution=&rateterm=&surryr=&mva=&rop=">  <!--- domain name , query string ---> <cfset domainname = listgetat(url , 1, "?")> <cfset querystring = listgetat(url , 2, "?")> <cfset querystring = listremoveduplicates(querystring, "&")> <cfset newurl = domainname & "?" & querystring> 

output:

http://website.com/abc.asp?type=298&action=submit&product=&contribution=&rateterm=&surryr=&mva=&rop=&sortby=1&sortorder=2&pagenum=3&company=&state= 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -