Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

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

Recommended Posts

Posted

I've got an application setup that uses the NetTools plugin to make HTTP POSTs to API systems. The response data comes back as a name-value pair string. Here's an example of what comes back:

TIMESTAMP=2007%2d12%2d06T21%3a35%3a26Z&CORRELATIONID=e74307952e63b&ACK=Success&VERSION=3%2e200000&BUILD=1%2e0006&AVSCODE=X&CVV2MATCH=M&TRANSACTIONID=40F01918U88259749&AMT=8%2e79&CURRENCYCODE=USD

I was shocked to see that FM didn't offer anything for parsing strings like this built in. I was able to find a custom Split() function that works, except that you can't pull data based on the paramater names. You just have to tell it which numbered occurance of the Split you want. For example, in the given NVP string sample, if I wanted to pull out the TransactionID I'd have to use the following:

Split ( Split ( $ResponseString ; 8 ; "&" ) ; 2 ; "=" )

So as you can see it actually takes me 2 uses of the Split() custom function to get what I want. First it grabs the 8th occurance of data split by the & character, and then after it has that value it splits it again on the = character in order to give me just the value I'm looking for.

Not only is this very tedius, but I don't always know exactly which numbered occurance I'll need. It would be MUCH better if I could somehow grab the values based on their parameter names.

Any information on this would be greatly appreciated. Thanks!

Posted

I was shocked to see that FM didn't offer anything for parsing strings like this built in.

What, you expect them to foresee that someone might receive a string delimited by "=" and "&", and provide a special function for that? You have all the text manipulation tools you need, it's up to you to use them. Try something like this:


Let ( [

prefix = "TRANSACTIONID" ;



t = InputText & "&" ;

p = prefix & "=" ;

pos =  Position ( t ; p ; 1 ; 1 ) ;

start = pos + Length ( p ) ;

end = Position ( t ; "&" ; start ; 1 ) 

] ;

Case ( pos ;

Middle ( t ; start ; end - start )

)

)

Now just change the prefix to extract another parameter, or make yourself a custom function with inputText and prefix as the function's parameters.

Posted

Name/Value pairs are a very standard thing. I just would have thought FM would have had a function just like what you show which looks very similar to what I found here: http://www.briandunning.com/cf/559.

Posted

Name/Value pairs are a very standard thing.

I believe you meant they are very common. I am not aware of any standard that they should follow. I know I have seen many variations on the theme - some of them would fit the above formula, others not.

I don't think any other programming/scripting environment has such function, not even Excel (at least it didn't when I last used it), and for a good reason. This is a rather simple task that can be achieved with basic text functions. If someone needs it often, they can put it in a custom function. Real functions should be as general as possible, not narrowed down to a specific task - no matter how common.

Posted

Yes, I did mean common.

Both PHP and Classic ASP have functions that handle this for you. I can't remember the exact function name without looking back at my code, but if you have a name/value pair string you can load it into this built-in function and it will return an array of the data with the parameter names. Then when you want that value you can call it by name.

I was expecting to have something like this already built into FM. The custom function I found is very similar to what you've shown me and it's working for me.

Thanks for your response...I just realized I didn't thank you in my last response.

Posted

I don't want to argue this to death, so let me just point out that Filemaker 9 has app. 250 functions altogether. Excel in version 4 had around 700. If new functions are added, I hope they will address more pressing issues.

This topic is 6197 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.