update an existing array of struct with the struct of array

Dan Schimo
Dan Schimo used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
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>
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 SchimoAnalyst

Author

Commented:
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

Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.


should have been...

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

Author

Commented:
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 SchimoAnalyst

Author

Commented:
Update-array-wrt-struct-2

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 SchimoAnalyst

Author

Commented:
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

<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

Dan SchimoAnalyst

Author

Commented:
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 ...
There was the same bug in my sample code (due to copy/paste) where the bad word was missing from the replace()

Also, I had to add delmiter=" " (space) to the badWord CLOOP


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

Open in new window

Dan SchimoAnalyst

Author

Commented:
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.


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.


Dan SchimoAnalyst

Author

Commented:
Sorry , I didn't get the last bit
Most Valuable Expert 2015
Commented:
It means the attribute name in your code is wrong.  Don't use delimiter use delimiterS (*note the "S")

    <cfloop index="badWord" list="#badWordList#" delimiterS=" ">
Dan SchimoAnalyst

Author

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

yes the logic worked...
Dan SchimoAnalyst

Author

Commented:
Thanks for the Help Both gdemaria and _agx
have a gr8 weekend !!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial