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.

Extracting string of text from one field with different variables

Featured Replies

I am trying to figure out how to extract a portion of a filename from a field, when the filenames differ.  It is for a file database.  This would be easy if all the files are named the same, but we have multiple different filenames based on the type of file it is.  So the idea is I have a "shot_name" field that pulls in the name from the file I am importing into FileMaker.  For instance, here are two of the filenames...one is for a traditional shot and one is for a development shot.

Traditional Shot:  BOG8515_150731_Line-Up
Development Shot:  BDC_dev9150_150721_Line-Up

Essentially the only portion of the shot I want is the following for each:

Traditional Shot:  BOG8515
Development Shot:  BDC_dev9150

I believe there would only be these two variables I would encounter, however the end of the filename may change from _Line-Up to _Change from time to time.  Is there a way to strip out only the shot name?  Can't quite wrap my head around how I would do that in a calculation field.  Any tips or advice would be greatly appreciated!

Would this be a correct statement: every filename is divided into several "tokens", separated by an underscore. You want to discard the last two "tokens".

If yes, try:

Let ( 
tokens = Substitute ( YourField ; "_" ; ¶ ) 
;
Substitute ( LeftValues ( tokens ; ValueCount ( tokens ) - 2 ) & ¶ ; [ "¶¶" ; "" ] ;  [ ¶ ; "_" ]  )
)

 

According to your description, the only persistent fact at all is that you need the part "Before" the 2. occurrence of "_" (underline).

How about this CustomFunction?

http://www.briandunning.com/cf/642

 

  • Author

Actually the token calculation worked perfectly!  Thanks so much for your help!  Worked like a charm!

  • Author

Okay...so I ran into another problem.  This works for one field but I need to extract the date from the filename...basically the 150731 or 150721 from the different file formats as well.  Is this possible using a similar token calculation?  If so that would be awesome.

I need to extract the date from the filename...basically the 150731 or 150721 from the different file formats as well.

That's a pretty trivial adjustment:

Let ( 
tokens = Substitute ( YourField ; "_" ; ¶ ) 
;
GetValue ( tokens ; ValueCount ( tokens ) - 1 )
)

 

  • Author

Amazing!  Thanks so much.  Worked perfectly.  Really confused about the positions but glad this worked.

Really confused about the positions

Why? There are either 3 or 4 "tokens" in your string. The date is always the one before last, so ValueCount ( tokens ) - 1 is the one to get.

Create an account or sign in to comment

Important Information

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

Account

Navigation

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.