RemoveValue ( Values ; ValuesToRemove )
Opposite version of FilterValues ().
Average rating: 4.4 (20 votes) Log in to vote
Koji Takeuchi - Show more from this author
TonicNote, Inc. https://tonicnote.com |
Function definition: (Copy & paste into FileMaker's Edit Custom Function window)
description:
Opposite version of FilterValues ().
ex.
theList = "aa¶bb¶cc¶aa¶dd"
RemoveValue ( theList ; "aa" )
-> "bb¶cc¶dd"
RemoveValue ( theList ; "a" )
-> "aa¶bb¶cc¶aa¶dd"
RemoveValue ( theList ; "bb¶dd" )
-> "aa¶cc¶aa"
Comments
Bruce Robertson Jun 25, 2015 |
||
Looks good but custom function editor won't accept it where the function name is identical to one of the argument names. | ||
Agnes Barouh, Tic Tac Jun 28, 2015 |
||
No, the function can't correctly works : for RemoveValue ( "aa¶bb¶cc¶aa¶aa¶dd" ; "aa" ) the result was "bb¶cc¶aa¶dd" and not "bb¶cc¶dd" Substitute ( "¶b¶b¶b¶" ; "¶b¶" ; "" ) give b Substitute ( "¶b¶¶b¶¶b¶" ; "¶b¶" ; "" ) give "" (The same comportement for PatternCount ) |
||
John Davis, Houston Jun 29, 2015 |
||
Modified the code to use a legal parameter name, and fixed the "sequential double entry" bug. RemoveValue ( Values ; ValueToRemove ) Let ( [ TARGET = ValueToRemove ; SOURCE = Substitute ( Values ; ¶ ; "¶¶" ) ; REMOVED = Substitute ( ¶ & SOURCE & ¶ ; ¶ & TARGET & ¶ ; "" ) ; RESULT = Substitute ( REMOVED ; "¶¶" ; ¶ ) ] ; RightValues ( RESULT ; ValueCount ( RESULT ) - 1 ) ) |
||
John Davis, Houston Jul 1, 2015 |
||
Change final RightValues line in my code (in comment directly above) to this: Right ( RESULT ; Length ( RESULT ) - 1 ) The Right function with Length is faster than RightValues with ValueCount. |
||
comment, VR Jul 5, 2015 |
||
Compare: SubstituteValues() http://www.briandunning.com/cf/851 |
||
Bruce Robertson Jul 6, 2015 |
||
Comparison result that I observe: RemoveValue ( "aa¶bb¶cc¶aa¶aa¶aa¶dd" ; "aa" ) => bb¶cc¶dd¶ SubstituteValues ( "aa¶bb¶cc¶aa¶aa¶aa¶dd" ; "aa" ;"") => bb¶cc¶aa¶dd¶ |
||
comment, VR Jul 6, 2015 |
||
Not anymore (thanks for the reminder, I meant to fix that but never got around to it). | ||
Koji Takeuchi, TonicNote, Inc. Jul 6, 2015 |
||
Bruce, Agnes and John, Thank you to valuable correction. I rewrote this using John's code and now it's perfect! |
||
comment, VR Jul 7, 2015 |
||
If you wanted, you could shorten this to just: Let ( remove = Substitute ( ¶ & listOfValues & ¶ ; [ ¶ ; "¶¶" ] ; [ ¶ & searchValue & ¶ ; "" ] ; [ "¶¶" ; ¶ ] ) ; Right ( remove ; Length ( remove ) - 1 ) ) P.S. Renaming variables, e.g. : TARGET = ValueToRemove ; does not add anything useful to the code. |
||
Koji Takeuchi, TonicNote, Inc. Jul 7, 2015 |
||
Thanks for recommendation. It's cool shorten version, but I still like to use "step by step" style in Let() function even if it's redundant because it feels much readable for me. (but I missed the code even thogh it's "step by step" ;-) Sorry, no offence. Thanks, again. |
||
Koji Takeuchi, TonicNote, Inc. Jul 12, 2015 |
||
I use this function today (sorry, it's first time...) and I found this is not useful! I rewrote this function for: - Removed unnecessary return at the end of result - Specifying multiple values on ValuesToRemove. (So I changed parameter name "ValueToRemove" to "ValuesToRemove") |
||
John Davis, Houston Jul 17, 2015 |
||
Hi Koji: Today I just discovered the trailing return bug in my previous code. I run this function in a looping script to remove multiple values. And now see it was building unnecessary trailing ¶s. Thanks for trying to fix it. However, you have now made this function into a different beast: a RECURSIVE FUNCTION. The beauty of your original code was that it was NOT recursive. Recursion has a limit, and I need to process HUGE lists and don't want to have to worry about reaching a recursion limit. So, I would use this non-recursive function to remove a single value and run it in a looping script to remove multiple values. I think you should have taken your new code and created a new custom function and named it RemoveValues and kept this one as RemoveValue to be a single-value non-recursive function. I've revised my original code to fix the trailing paragraph bug. I'll post the code in my next comment, if anyone is interested. It goes back to removing only one value from all the list. But what's important is that the following alternate code DOES NOT USE RECURSION. Thus, you can use it in a looping script and never have to worry about reaching a recursion limit. |
||
John Davis, Houston Jul 17, 2015 |
||
RemoveValue ( Values ; ValueToRemove ) NON-RECURSIVE, remove SINGLE-VALUE alternate code: Let ( [ TARGET = ValueToRemove; SOURCE = Substitute ( Values ; ¶ ; "¶¶" ); REMOVED = Substitute ( ¶ & SOURCE & ¶; ¶ & TARGET & ¶; "" ) ; COMPRESSED = Substitute ( REMOVED ; "¶¶" ; ¶ ); TRIMMED = Middle ( COMPRESSED ; 2 ; Length ( COMPRESSED ) - 2 ); RESULT = TRIMMED ] ; RESULT ) |
||
John Davis, Houston Jul 17, 2015 |
||
Well Koji, I've got to hand it to you. I tested your function over a list of 1 million values, and it didn't fail. Got the same number of results as my looping script with the non-recursive function. And the benchmarks were similar. Can you enlighten me on your recursion? Is there no limit restriction on this function? |
||
Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.