Jump to content

Substitute / Delete values Feeded by List


This topic is 1967 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hello, 

I m trying to set up a script the goal is to delete or substitute  some words form a Title (field) feeded by a $list (list of word located in different table)

exemple I Have  a title in table A : - Memory drive flash pen stick 8gb 16gb 32gb 64 gb

And I have a list of words in table B : 8go 16 go 32 go 64 gb

Output, what I would like to get is : "Memory drive flash pen stick"

 

Each title will have his own list with same reference, there is also a trick because as you can see Gb could mean Go, so I think the best is delete all words matched (8, 16, 32, 64 ...)  then I have another script who will delete duplicate words in the field (title) 

 

Thank you :) 

title_sub.fmp12

Link to comment
Share on other sites

I don't understand your example. "16gb" is not the same as "16 go". We can ignore the case,  but not the difference between "b" and "o", or the space in the middle .  Especially not the space in the middle, since your list is space-delimited.

You need to give us some clear-cut rules regarding what you want to consider a match - and be careful not to make them too wide, or you'll end up deleting things you want to keep. Computers have no common sense; they follow the instructions given to them literally.

Link to comment
Share on other sites

I see, it s difficult to choose ><  how to do it better, so I think the best way will be :

separate word with space, for exemple make  a list from the list for words with space : 8go then, 16, then "go", then 32 ...  delete them from the title. You re absolutely right about getting wide ))) if I see that it delete word unwanted I can always go back and limit to the first list. 

 

thank you Comment 

Link to comment
Share on other sites

Well, that should be easy enough to do with a script like:

Set Variable [ $blacklist; Value:List ( Child::Value ) ]
Set Variable [ $n; Value:WordCount ( Parent::Words ) ] 
Loop
	Set Variable [ $i; Value:$i + 1 ]
	Exit Loop If [ $i > $n ]
	Set Variable [ $word; Value:MiddleWords ( Parent::Words ; $i ; 1 ) ] 
	If [ IsEmpty ( FilterValues ( $word ; $blacklist ) ) ]
		Set Variable [ $output; Value:List ( $output ; $word ) ] 
	End If
End Loop
Set Field [ Parent::Result; Substitute ( $output ; ¶ ; " " ) ]

I have used Parent::Words as the name of the field that contains the space-separated words, and Child::Value as the name of the field that contains a word to be removed.

Link to comment
Share on other sites

For some reason, your counter $i does not increase, and I cannot figure out why. I have  disabled your:

Set Variable [ $i; Value:$i + 1 ]

and replaced it with my own, and that got the script out of the infinite loop. But I am unable to detect the difference between them.

You also selected the wrong field when setting the $word variable.

--
P.S. You have the Advanced version; use the debugger with Data Viewer to de-bug your scripts.

 

 

title_sub2.fmp12

Edited by comment
Link to comment
Share on other sites

did you ever get this issu :

when I run GetAsNumber ( List ( field::field ) )

I don't have a liste, I have numbers after numbers without space  :726956483624

instead of :

72

69

56

48

36

24

Link to comment
Share on other sites

 input : 

72LDs

69LDs

56LDs

48LDs

36LDs

24LDs

output with Getasnumber "GetAsNumber (  List ( variante::taille ) )   " 726956483624

what I would like is a list :

 

72

69

56

48

36

24

it s partly related, it s better if I open a new topic ? with a project file for exemple ? 

here is an exemple

getasnumber.fmp12

Link to comment
Share on other sites

If you want to apply GetAsNumber() to every item in the list individually, you must do exactly that: loop over the list, and convert each item to a number in turn.  In a script, that would look like something like (untested, pseudocode):

Set Variable [ $input ; List ( variante::taille ) ]
Set Variable [ $n ; ValueCount ( $input ) ] 
Loop
  Set Variable [ $i ; $i + 1 ]
  Exit Loop If [ $i > $n ]
  Set Variable [ $output ; List ( $output ; GetAsNumber ( GetValue ( $input ; $i ) ) ) ] 
End Loop

 

Link to comment
Share on other sites

This topic is 1967 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.