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.

'Substitute' function and wildcards

Featured Replies

I need to create a field which looks at an existing field and strips out everything in it which is between chevrons, i.e. replace with nothing.

How do I put this into the function? I've tried asterisks and it doesn't understand them, I guess because in a function they mean multiplication!

First post, hope someone can help!

Emma

Moderately straightforward if there is only one pair of chevrons - call the fields Stripped and Chevrons

Stripped = Left (Chevrons, Max(Position(Chevrons,"<",1,1)-1,0))

& Right(Chevrons,Length(Chevrons) - Position(Chevrons;">",1,1)))

The max takes account of no chevrons.

If there is a possibility of more than one unspecified number of chevrons then I think you need a recursive or looping method. That is treat the above as an intermediate calculation and keep doing it until there are no chevrons left.

By the way - I am using version 8. I think the formula is OK for version 5.

  • Author

There could be as many as 20 chevroned tags in the source field (it's linked to a QuarkXPress document and the tags are Quark styles).

Your solution doesn't work for me in v5 - the Max function requires a field name only as a parameter. I'm working on adapting it (leaving out the Max seems to help!) just to isolate a couple of chevrons but it seems very complicated. Is it really not possible to just put in a wildcard?:)

Slim Jim,

I haven't used the Max function much, if ever. How does it function here?

Emma,

Wildcard "*" is used in searching, not in calculations. If you have 20 chevrons and you don't want to use a script you could use a series of calcs. You just have to be sure to account for the maximum possible occurrences of Chevrons.

Stripped1 = Left (Chevrons, Position(Chevrons,"<",1,1)-1,0))

& Right(Chevrons,Length(Chevrons) - Position(Chevrons;">",1,1)))

Stripped2 = Left (Stripped1, Position(Stripped1,"<",1,1)-1,0))

& Right(Stripped1,Length(Stripped1) - Position(Stripped1;">",1,1)))

Stripped3 = Left (Stripped2, Position(Stripped2,"<",1,1)-1,0))

& Right(Stripped2,Length(Stripped2) - Position(Stripped2;">",1,1)))

Stripped4 = Left (Stripped3, Position(Stripped3,"<",1,1)-1,0))

& Right(Stripped3,Length(Stripped3) - Position(Stripped3;">",1,1)))

etc....

This might be excessive for more than one field you want to strip, but for one field that you are going to use a frequently and want it to refresh on the fly instead of having to run a script it's not so bad.

Slim Jim,

I haven't used the Max function much, if ever. How does it function here?

Here I am calculating using the Position function which can return a value of 0 and then subtracting 1 will produce a negative value in the number of characters for the Left function. I have no idea how the Left function will react to a negative number of characters so taking Max(...;0) will produce a 0 whenever the Position is 0.

Someone on these forums (I think it was comment) pointed out that you can use constants within a Max even though the Filemaker help file explicitly states that the arguments of the Max should be

any related field, repeating field, or set of non-repeating fields; or an expression that returns a field, repeating field, or set of non-repeating fields.

Just for the record: I went back to FMP version 3 and the Max function works in the same way, i.e, you can Max a field and a constant value, e.g.

Max(field,10)

will return the larger of 10 and the value of field. But, it will not accept an expression instead of a field.

Edited by Guest

To get back to Emma's original question. I think a scripted solution is the answer. I have tested this in version 3 so it should be OK.

Name the text field that receives the input as Field1 and the intended output field as Field2 add in an extra field Field3 for use in the script. (Field3 can be golbal text)

Use the following script


Set Field["Field2,"Field1]

Loop

   Exit loop if ["Position(Field2,"<",1,1) = 0"]

    Set Field["Field3","Left(Field2, Position(Field2,"<",1,1)-1)& Right(Field2,Length(Field2) - Position(Field2,">",1,1))"

    Set Field("Field2","Field3")

End Loop

This script loops through the field removing pairs of chevrons and the text between them until there are no more "<" left to remove.

If you want this to run through all the records then add

Find All

Go to Record/Request/Page[first]

Loop

on the front of the script and

Go to Record/Request/Page[Exit after last, Next]

End Loop

on the end of the script.

You need a custom function, not a script. Look at the field substitute custom function in the custom function section of this forum. It does EXACTLY what you're looking for.

This would only be helpful if you could make a Custom Function work in FM 5. :wink2:

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.