Avatar of Dan Schimo
Dan Schimo
Flag for United States of America asked on

update an existing array of struct with the struct of array

Hello Experts,

i am need of urgent help where i have a array of Struc whose struct element has to updated by the First array of the Struct of arrays.
Attached is the Image of both .
   Update-array-wrt-struct
The KEY "V" in the First Dump(array) needs to be replaced by the Second array below it. in such a way that Eg : dissorder in the First array should be replaced by the "Disorder" of the fiirst element in the Array
ColdFusion Language

Avatar of undefined
Last Comment
Dan Schimo

8/22/2022 - Mon
gdemaria

Your first array structure (in red) is showing two array positions, but you don't say what to do with the 2nd position.  So I have done nothing with it.

This code will look at the V location of the array at position 1 to determin the badword, it will look for the bad word in a structure called Words and take the 1st position from the array that it contains...

<cfset pos= 1>

<cfset badword= data[pos].v>
<cfif structKeyExists(words, badword)>
       <cfset data[pos].v = words[badword][1]>
</cfif>
gdemaria

Perhaps this is what you wanted.

This grabs the misspelled word from the red structure (i called data)
looks for it in the second structure of word suggestions (i called words)

It then replaces the v value of the 1st and 2nd element of the red array with the correctly spelled word....

<cfset badword = data[1].v>
<cfif structKeyExists(words, badword)>
   <cfset goodWord = words[badword][1]>
   <cfset data[1].v = goodWord>
   <cfset data[2].v = replace(data[2].v,goodWord)>
</cfif>
Dan Schimo

ASKER
gdemaria

I tried doing this with the actual names of the objects..
 I am getting a "Parameter validation error for the REPLACE function. "
<cfset badword = arguments.searchData.arrCriteria[1].v>
<cfif structKeyExists(correctedTerms, badword)>
   <cfset goodWord = correctedTerms[badword][1]>
   <cfset arguments.searchData.arrCriteria[1].v = goodWord>
   <cfset arguments.searchData.arrCriteria[2].v = replace(arguments.searchData.arrCriteria[2].v,goodWord)>
</cfif>

	<cfdump var="#arguments.searchData.arrCriteria#">

Open in new window

Your help has saved me hundreds of hours of internet surfing.
fblack61
gdemaria


should have been...

   replace(data[2].v,badword,goodWord)>
Dan Schimo

ASKER
That works :)  But , the Array Len are not static,

I.e the data array can be any number of rows the sturct in it and also the suggetions (Words) can be of any number of structures. How will we go forward in this case .
Dan Schimo

ASKER
Update-array-wrt-struct-2
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
gdemaria


We already handle the CorrectedWords part, it doesn't loop, we are simply looking to find the bad word on the list and grab the #1 option of correctedWords, that is done in these two lines...


<cfif structKeyExists(correctedTerms, badword)>
    <cfset goodWord = correctedTerms[badword][1]>


But what about the first structure, in your first example it seems that array position 2 was just an expantion of position 1 (they both were for the same incorrect word).

Can you explain the structure of this array?

Dan Schimo

ASKER
Sorry for the Confusion , The position 2 of the First array is not the Expansion . it could be of any number of words

, eg,  first array
 arraypos[2].V = mispeeled Direcktor meerger

then all the 3 words need to be replaced with the reference to the good words struct
gdemaria


<cfloop index="pos" from="1" to="#arrayLen(arguments.searchData.arrCriteria)#">
  <cfset badwordList = arguments.searchData.arrCriteria[pos].v>
  <cfloop index="badWord" list="#badWordList#">
     <cfif structKeyExists(correctedTerms, badword)>
       <cfset goodWord = correctedTerms[badword][1]>
       <cfset arguments.searchData.arrCriteria[pos].v = replace(arguments.searchData.arrCriteria[pos].v,goodWord)>
     </cfif>
  </cfloop>
</cfloop>

Open in new window

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Dan Schimo

ASKER
Update-array-wrt-struct-3
gdemaria
if you see the screen shot the logic has missed the "dissorder" in the 2 Position of the First array ...
ASKER CERTIFIED SOLUTION
gdemaria

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Dan Schimo

ASKER
Sorry but I could get to the Error ,

Attribute validation error for tag CFLOOP.

It does not allow the attribute(s) DELIMITER. The valid attribute(s) are ARRAY,CHARACTERS,CHARSET,COLLECTION,CONDITION,DELIMITERS,ENDROW,FILE,FROM,INDEX,ITEM,LIST,QUERY,STARTROW,STEP,TO.
gdemaria



It does not allow the attribute(s) DELIMITER. The valid attribute(s) are


ARRAY,CHARACTERS,CHARSET,COLLECTION,CONDITION,DELIMITERS,ENDROW,FILE,FROM,INDEX,ITEM,LIST,QUERY,STARTROW,STEP,TO.


Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Dan Schimo

ASKER
Sorry , I didn't get the last bit
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Dan Schimo

ASKER
Sorry abt tht I did not pay attanetion to the response...

yes the logic worked...
Dan Schimo

ASKER
Thanks for the Help Both gdemaria and _agx
have a gr8 weekend !!
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck