* String substitution function needed

Questions regarding use of any Version of Family Historian. Please ensure you have set your Version of Family Historian in your Profile. If your question fits in one of these subject-specific sub-forums, please ask it there.
Post Reply
avatar
Gary_G
Megastar
Posts: 841
Joined: 24 Mar 2023 19:05
Family Historian: V7

String substitution function needed

Post by Gary_G »

The FH7 function set does not contain a function that allows one or more occurrences of a string to replaced with another string within a text metafield.

A trivial example is changing, "Ottawa, Ontario, Canada" to "Ottawa. Ontario. Canada", by substituting periods for commas. This example has a known number of occurrences of the target string "," (comma), but a known number of occurrences cannot be assumed in arbitrary user input.

In the case of an unknown number of substitutions, it does not appear to be possible to use a combination of the existing FH7 functions to achieve the desired result.

Is there a known solution or should I enter a Wishlist request for the addition of such a function?

[Note that this is not quite the same issue as in,"Does FH7 have a way of replacing characters in a text string?", viewtopic.php?t=21761. Here I am trying to formulate my question in a way that will help to determine if a Wishlist request is needed.]
Gary Gauthier
Hunting History in the Wild!
User avatar
tatewise
Megastar
Posts: 28594
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: String substitution function needed

Post by tatewise »

Gary, I've moved this from the Sources, Citations & Repositories forum that does not seem relevant.

You are correct that the FH Functions do not support string substitution in Expressions.
So automated string substitution cannot be performed in such as Source Template Format expressions.

There is a Wish List Ref 547 Run Plugins via Expressions that would allow a string substitution plugin to be invoked in an Expression as if it was a Function.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
avatar
Gary_G
Megastar
Posts: 841
Joined: 24 Mar 2023 19:05
Family Historian: V7

Re: String substitution function needed

Post by Gary_G »

Wasn't quite sure where to locate this question. Thanks for moving it.
There is a Wish List Ref 547 Run Plugins via Expressions that would allow a string substitution plugin to be invoked in an Expression as if it was a Function.
I'll take a look, but that almost sounds like using a baseball bat to kill a fly. The larger wish would likely be harder for CP to implement than a more restricted substitution capability. That, in turn, might affect the potential for anything to be done to resolve the issue of substitution.
Gary Gauthier
Hunting History in the Wild!
User avatar
tatewise
Megastar
Posts: 28594
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: String substitution function needed

Post by tatewise »

You are almost certainly correct but a lot more can be done with a baseball bat than just kill flies! :D
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
ColeValleyGirl
Megastar
Posts: 5546
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: String substitution function needed

Post by ColeValleyGirl »

If you want an expression, I'm assuming you want to use it in Sentences, Queries, Diagrams etc. to transform data for display in a different format form that in which you've entered it (or imported it).

Is the use case that you want it to appear differently in different places? In which case fixing your data once won't help, but fixing their data would be the easiest route for must people to go.

I'm not personally convinced by the Wish List request Mike referred to. It seems to me that the number of plugins that could be invoked this way would be small -- and perhaps restricted to 'custom plugins' to solve a one-off problem for an individual user. I note that it received no discussion or expressions of support in the 5 months between being raised as a request and being moved to the Wish List. The process was different then, but it would not have made it to the Wish List in that state if it had been raised today. (I don't object to it per se, just believe it's unlikely to be implemented).

I'd rather see some more string transformation functions available.
avatar
Gary_G
Megastar
Posts: 841
Joined: 24 Mar 2023 19:05
Family Historian: V7

Re: String substitution function needed

Post by Gary_G »

Just a note....
I knew the noted Wishlist item sounded familiar. I posted a comment a while back.
Gary_G on Wednesday 12th April 2023 said:
FH7 is somewhat lacking in standard string functions. Being able to define those that are missing would make some templates possible and greatly simplify/shorten most.
Gary Gauthier
Hunting History in the Wild!
avatar
Gary_G
Megastar
Posts: 841
Joined: 24 Mar 2023 19:05
Family Historian: V7

Re: String substitution function needed

Post by Gary_G »

Helen;

I can't alter the metadata field content, as it is used as is in the Footnote section of the template in which it is entered. However; it is also reversed and should have periods instead of commas, when it is used a second time in the Bibliography section.

Reversal isn't an issue with the existing FH7 predefined functions, but the substitution is not possible. One can't predict the number of commas in the entered string. That would be needed to kludge a way using the existing functions.

So; basically, I need an actual "SUBST" string function. The way it is implemented is not so important as its availability.
Gary Gauthier
Hunting History in the Wild!
User avatar
tatewise
Megastar
Posts: 28594
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: String substitution function needed

Post by tatewise »

ColeValleyGirl wrote: 13 Nov 2023 15:52 I note that it received no discussion or expressions of support in the 5 months between being raised as a request and being moved to the Wish List.
FYI: It has attracted 19 Votes since then with an Average Rating of 4.4 which puts it joint 6th on that ranking.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
ColeValleyGirl
Megastar
Posts: 5546
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: String substitution function needed

Post by ColeValleyGirl »

tatewise wrote: 13 Nov 2023 16:38
ColeValleyGirl wrote: 13 Nov 2023 15:52 I note that it received no discussion or expressions of support in the 5 months between being raised as a request and being moved to the Wish List.
FYI: It has attracted 19 Votes since then with an Average Rating of 4.4 which puts it joint 6th on that ranking.
FYI, I could see that. But I wonder how much different the Wish would be -- and how much better its opportunities and limitations would be understood if it had received some discussion. That is however water under the bridge.
Post Reply