ISO FileMaker Magazine: FileMaker Video Tutorials, Templates, Help & More

FileMaker Deals

Video Browser

Scriptology Video Browser

Tools & Resources

Array

Simulating a Basic Key / Value Array

Posted by: aflgenx / Thursday, September 27, 2007 – 9:04pm

Alright guys, been busy so pardon the greater than one month gap. This is more on the whole numeric addressing issue we have with repeating vars and fields... its really annoying and puts limits on what can be achieved.

So, we want to simulate text based key's that are available in every programming language known to man - one method I don't mind (though i haven't extensively run speed tests on it):

Custom Function: getValueFromArray( array ; key)
Let( [
newList = Substitute( array ; "\," ; "|||" ) ;
newList = ¶ & Substitute( newList ; "," ; "¶" ) & ¶;
newList = Substitute( newList ; "|||" ; "," );
keyStart = Position( newList ; ¶ & key & "=>" ; 1 ; 1 ) ;
valueStart = keyStart + Length(key)+3;
valueEnd = Position( newList ; "¶" ; valueStart ; 1 )];
If( PatternCount( newList ; ¶ & key & "=>" ) ; Middle( newList ; valueStart ; valueEnd - valueStart) ; "?" )
)

Method for setting the key / value array:
$array = "key=>value,sentance=>I am a value\, values are cool!!,key3=>\"value3\""

Now, so lets say we wanted to extract the value for sentance from that array:
getValueFromArray( $array ; "sentance" ) which would return: I am a value, values are cool!!
getValueFromArray( $array ; "key3" ) would return "value3".

I hope this has been a fun and eductational experience ;)

Cheers guys, will try build a bit on this and run some speed tests over the next few weeks, in the mean time, behave yourselves!!

Filed under: |
Syndicate content