Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How to parse name-value pair strings within FM...???

Featured Replies

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!

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.

  • Author

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.

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.

  • Author

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.

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.

Create an account or sign in to comment

Important Information

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.