Jump to content

Recursive Substitue And Replace


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

Recommended Posts

Part 1 Request

Starting out with text in a field (global)

===

text text cat text text mouse text text

text text text dog text text text

text 123 inches text text bird text dolphin

horse! text text text human text text DOG text

===

Then I have this table of keywords (This is a table w/ a record for each keyword.)

===

cat

mouse

dog

bird

dolphin

DOG

horse

inches

human

What I would like learn how to build a custom recursive function that would

firstly enable me to do this..

===

text text [color:"red"]cat text text [color:"red"]mouse text text

text text text [color:"red"]dog text text text

text 123 [color:"red"]inches text text [color:"red"]bird text [color:"red"]dolphin

[color:"red"]horse! text text text [color:"red"]human text text [color:"red"]DOG text

===

basically highlight text that are in the table this will allow this list to be abstract and

extensible.

Part 2 Request

Taking this newly formatted field the applying a replace rules against it.

In the keyword table there is another field with the replacement word.

===

keyword == replace == flag

cat =======> feline

mouse =====> Mice

dog ======> Canine

bird ======> null

dolphin ====> FISH

DOG ======> puppy

horse! =====> glue.

inches =====> " =====> X

human =====> null

Then in a separate field the following would be the result

===

text text [color:"blue"]feline text text [color:"blue"]Mice text text

text text text [color:"blue"]Canine text text text

text 123[color:"blue"]" text text text [color:"blue"]FISH

[color:"blue"]glue. text text text text text [color:"blue"]puppy text

===

If there is the term "null" in the replace field the word is eliminated.

Now if there is a flag in the last column it will also strip out any preceding space.

this needs to be case sensitive and take into consideration the placement of a word

cause it could be surrounded by different leading and trailing separators such as a space

or paragraph symbol.

Thanks I am trying to understand building a recursive function just haven't starred at it long enough to figure it out your guidance is appreciated.

Link to comment
Share on other sites

Hi Stephen,

As I was left alone in this ugly office with a computer with FM5 today, I tried it starting from the old way.

I would say you may come with a better solution with 7 by involving Get(CalculationRepetitionNumber) in place of the hardcoded iterations in the demo file here.

Of course, having it done by recursions through a custom function could be very powerful, but I couldn't try this.

Highlighting is quite easy with the new Text Functions, so I skipped this step here.

HTH

ForStephen.zip

Link to comment
Share on other sites

Thanks Ugo,

I have it setup right now thru a script where it will loop thru the records in the table and basically do a nested substitute. That seems to work well but because it has to loop thru records I am thinking it is slower.

But then I had the thought if I could do say one loop at startup (since the library of words seldom changes) put all that in a return separated list. Then w/ recursion go thru that list and on pasting

into the text field have it auto format the highlighted words. Then also the calculated text would also update.

I just have to stare longer at recursion as it pertains to fields.

Link to comment
Share on other sites

Ok Here is the solution - curious if there is any way to make it even more "tighter" code?

there are 6 Fields


search list , replace list, flag list, hilite data, new data, and sample data.

and 3 custom functions...

LineValue (textlist ; lineNum)

Substitute( MiddleValues ( (textList &

Recursive.fp7.zip

Link to comment
Share on other sites

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