Jump to content

Auto-Enter Calculation to extract text of varying length found between two characters.


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

Recommended Posts

Hello to you all.
I am looking for an Auto-Enter Calculation to extract text of varying length found between two characters.
I have two text fields:
The first field is named [FileName] and contains image file names e.g. "NIK000223_hab-ven.jpg". The second field is named [ImageType].
Now, what I need is to extract from filed [FileName] and insert to field [ImageType], the any given text that is found between the underscore character “_” and the period character “.”
I will greatly appreciate any help.
Thank in advance.

Link to comment
Share on other sites

Try the following formula:

Let ( [
start = Position ( FileName ; "_" ; 1 ; 1 ) + 1 ;
end = Position ( FileName ; "." ; start ; 1 )
] ;
Middle ( FileName ; start ; end - start )
)

Why do you need this to be an auto-entered calculation? Why not simply use a calculation field?

Link to comment
Share on other sites

Oh! Perfect, works like a dream.
Thank you very much. I truly appreciate your help, you saved my day. I thought the solution was a Let calculation which so far I haven't managed to master.
Thanks again.
No any particular reason really, it could just as well be a calculation field. Does it matter? 

Link to comment
Share on other sites

41 minutes ago, asterix said:

I thought the solution was a Let calculation

Not really. The Let() function doesn't actually do anything except allow you to make your calculation more readable and - most importantly - avoid repeated calculations of the same thing. In this case, the start position is used for calculating both the end position and the length of the text to extract. Without using Let(), the calculation would have to be:

Middle ( 
FileName ; 
Position ( FileName ; "_" ; 1 ; 1 ) + 1 ; 
Position ( FileName ; "." ; Position ( FileName ; "_" ; 1 ; 1 ) + 1 ; 1 ) 
- ( Position ( FileName ; "_" ; 1 ; 1 ) + 1 )
)

which is both difficult to read and wasteful as it calculates the same thing 3 times.

 

41 minutes ago, asterix said:

it could just as well be a calculation field. Does it matter? 

In this case, not so much - except it allows the user to override the calculated value. In other cases it can make a crucial difference, because only a calculation field can be unstored. Calculation fields also have the advantage of the formula being visible when browsing the fields list in Manage Database.

I would suggest this rule of thumb: always use a calculation field, unless you have a good reason to use an auto-entered calculation.

 

Edited by comment
  • Like 2
Link to comment
Share on other sites

On second thoughts I do have a reason for the field been text. It has a drop-down value list in order to select it's values in find mode.
And thanks for the advice, it is always useful to acquire new knowledge 🙂

Link to comment
Share on other sites

13 minutes ago, asterix said:

I do have a reason for the field been text. It has a drop-down value list in order to select it's values in find mode.

What makes you think you cannot format a calculation field as a drop-down list?

 

Edited by comment
Link to comment
Share on other sites

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