Jump to content

Parsing out a substring... multiple instances...?


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

Recommended Posts

Hello,

 

I am a FM newbie and have been scouring the web for an answer to this problem:

 

I want to eliminate the text within parentheses in a string, but I want to eliminate all instances:

 

ORIGINAL STRING:

This is a test of the (emergency) broadcast system. (It is only a test). Remain calm.

 

DESIRED STRING: 

This is a test of the broadcast system. Remain calm.

 

Can anyone help?

 

Also, is it possible to tie the function or script to a field so that when the ORIGINAL string is put into the field, the field does the conversion automatically?

 

thanks very much in advance,

 

SB

Link to comment
Share on other sites

I want to eliminate the text within parentheses in a string,

 

If you eliminate all text within parentheses, you will end up with:

"This is a test of the  broadcast system. . Remain calm."

You can clean up the runs of spaces by using TrimAll() on the result, but the extra period in your example is outside the parentheses.

 

 

This would probably be best done with a custom recursive function, but you can try a hack in the form of:

Let (
formula = Substitute ( Quote ( Textfield ) ; [ "(" ; ""  & /*" ] ; [ ")" ; "*/ "" ] )
;
Evaluate ( formula )
)

Note that this will fail miserably if the text contains unbalanced parentheses.

 

 

Also, is it possible to tie the function or script to a field so that when the ORIGINAL string is put into the field, the field does the conversion automatically?

 

You can set the field to auto-enter a calculated value (using the above formula), replacing the existing value.

Link to comment
Share on other sites

This topic is 2876 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
 Share

×
×
  • Create New...

Important Information

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