Jump 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.

String with parameters in it à la "printf"

Featured Replies

Hi,

Is there any function that can return a string in which there are some parameters? Like a printf in C.

Example of what the function could look like :

C style

printf("The sum of %d and %d is %d", 2, 5, 7)

FM style

printf(myString, lstParameters)

I guess the in FM the function should receive a list instead of parameters.

BTW, I know that printf doesn't return a string...

Thanks

FileMaker doens't have any native functions for that purpose (as I can recall). The easy way might be to use a Substitute function:


Let([

a = 2;

b = 5;

c = 7

];

Substitute( "The sum of _a and _b is _c"

; [ "_a"; a ]

; [ "_b"; b ]

; [ "_c"; c ]

)




But that isn't very dynamic.  You'll need to use a recursive function or CustomList to do this with a dynamic amount of placeholders.



I'm not aware of any pre-existing custom functions for this either, but I haven't checked.  The place to check is in the libraries at BrianDunning.com and fmFunctions.com. 



Here is an example: 




/*

printf( string ; placeholder ; replacementValues )

*/



Let([



sPlaceholder = Position( string; placeholder; 1; 1 ) ;

stringNew = 

Replace( string

; sPlaceholder

; Length( placeholder )

; GetValue( replacementValues; 1 )

)



];



Case(

	

	//--Another placeholder and value exist--

	Position( string; placeholder; 1; 2 ) > 0

	and ValueCount( replacementValues ) > 1

		; printf( stringNew ; placeholder ; RightValues( replacementValues ; ValueCount( replacementValues ) - 1 ) )

	

	//--Additional branches for error trapping can be added here--

	

	//--Else, return result--

	; stringNew



) //End Case



) //End Let

Is that what you're looking for? I haven't really tested this, but it might be enough to get your started.

  • Author

Yes it is.

I will try and tweak it this week and get back with the results.

Thanks

  • Author

Your function seems to work quite well. I think you should consider publishing it on fmfunctions or/and briandunning site.

In my case, this function will be useful in a multilingual project. Especially, where I need to replace some values inside a string.

Thanks!

Edited by Guest

I'm glad it's working for you!

I normally wouldn't post a function until it's been proven in production or heavy usage, but I might take your recommendation - this one seems harmless enough.

Create an account or sign in to comment

Important Information

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

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.