Page 1 of 1

Does FH7 have a way of replacing characters in a text string?

Posted: 03 Apr 2023 19:45
by Gary_G
I am constructing a Caption using elements from my entered meta-fields and hope to also use it as a filename.
However; some of the elements have one or more embedded spaces. That may not "play nice" with Windows or Mac.
I looked at the available function-list and could not see any function to replace the spaces with an underscore.
Then I looked to see if I could combine functions to do the job. Still no luck.
I could be missing something. If anyone knows how to do a search-and-replace, please let me know.

Re: Does FH7 have a way of replacing characters in a text string?

Posted: 03 Apr 2023 19:51
by tatewise
Edit > Find and Replace... would work but probably finds too many occurrences of space characters.
My Search and Replace plugin would work and can focus on a much narrower set of fields.

Re: Does FH7 have a way of replacing characters in a text string?

Posted: 03 Apr 2023 20:26
by Gary_G
I wasn't aware that a plugin could supply additional functions that one could use from within a template to manipulate field contents. If it can, please tell me more. The generated template caption is currently created from template meta-fields, but some of those meta-field values have spaces. Spaces mean that I likely ought not to use such a caption for an associated filename. However; if I can substitute underscores, then the caption can be directly cut and pasted as the filename for the associated image.

Re: Does FH7 have a way of replacing characters in a text string?

Posted: 03 Apr 2023 20:44
by tatewise
Sorry Gary, I got the impression that you were discussing a manual process.
I don't understand how you are automatically generating a caption from metafields using a template.
Where does that caption exist?
Perhaps you don't mean caption but Source Record Title derived from the Record Title Format: template?
If so then it would help us understand better if you used the FH field names rather than caption which in FH refers to the descriptive text that appears under images.

Please clarify which steps in the process you describe are automatic and which are manual.

If the copying of caption to filename is automated with a plugin then it could substitute spaces with underscores and check any other filename rules. There are existing plugins that perform similar operations on Media records where the record Title needs to be converted to a valid File link filename.

Re: Does FH7 have a way of replacing characters in a text string?

Posted: 03 Apr 2023 21:52
by Gary_G
Sorry, Mike. I'm still getting used to the names in FH7. I have an auto-generated "Record Title Format" that is composed of meta-field values from the template.

Eg. <France__{Repository}__{Cote_microfilm}__({Commune}_{Event_Type}_{Registration_Date:YEAR})__{Image_no}_({Accession_Date})>

{Cote_microfilm} is the call number of a microfilm in the French Departmental Archives. Sometimes it has embedded spaces, which likely shouldn't be used in filenames despite Windows and Macs not choking on such filenames.

As I'm still clueless about the Lua language, I'm not sure if it has the concept of declaring functions to be public. That is, potentially making them available to other parts of the code such as that which processes meta-field content. Would be nice if it did. The available function-set seems to have some holes in its string-processing capabilities.

Re: Does FH7 have a way of replacing characters in a text string?

Posted: 03 Apr 2023 22:20
by tatewise
You have only described half the process of creating the Source Record Title from the template.
Are you then going to create a filename from the Source Record Title by manually copying that field?
Wherever you paste that filename (presumably in a Media record File link field) that can be converted afterwards from spaces to underscore by using the Search and Replace plugin.

No, the Lua language is simply used to code the plugins. Plugins cannot be declared as public functions.
BTW: There is a Wish List entry that requests such a feature.
I agree that the FH Functions are poor on string processing.

Re: Does FH7 have a way of replacing characters in a text string?

Posted: 03 Apr 2023 23:52
by Gary_G
Mike;

Thanks for the quick reply.

Yes; I was planning to cut and paste the filename, but I'm open to better solutions.

While waiting, I think I found a solution that can be auto-generated and won't require "massaging".
Apparently Windows and Macs are much less restrictive than they used to be and will happily accept the following;

France; Archives départementales de l'Eure; cote 8 Mi 5610 (Chauvincourt-Provemont_Birth_1866); vue 65-66 (6 December 2022).jpg

The semi-colons break the name into its component parts, so that commas can be used within them. Spaces appear not to be an issue anymore. That said; the ISO 9660 std. for CD/DVD filenames hasn't changed. It's SO restrictive that absolutely NONE of the typical genealogical filenames could hope to meet it. I believe that most CD/DVD players now utilize a much more relaxed set of rules, as I' sure I've seen them record anything the O/S can. So maybe that is not an issue. As I will likely pass my files electronically, I think what I've shown should be OK.

Re: Does FH7 have a way of replacing characters in a text string?

Posted: 04 Apr 2023 09:42
by tatewise
I'm still a bit unclear about why you need to create a Source Record Title to produce a filename and how the file is used.
How are you intending to use the file that has that filename?
Is it a file that already exists or one you are creating?
Will it be a Media item in your FH Project data?

Re: Does FH7 have a way of replacing characters in a text string?

Posted: 04 Apr 2023 16:23
by Gary_G
Mike;

I already have files in an external structure that have a certain filename.
As they are a 1:1 match for Splitter sources, I wanted to generate the same name within FH7.

Re: Does FH7 have a way of replacing characters in a text string?

Posted: 04 Apr 2023 16:47
by tatewise
That has not really answered all my questions. Will those files become Media linked to the Source record in your Project?

Re: Does FH7 have a way of replacing characters in a text string?

Posted: 04 Apr 2023 20:12
by Gary_G
Mike;

I'm not sure where you're going with the questions, so I'll just do my best to answer blindly.

How are you intending to use the file that has that filename?
> I want it to show in reports and possibly on a webpage.

Is it a file that already exists or one you are creating?
> The file exists.

Will it be a Media item in your FH Project data?
> No. In an external file structure.

...

Will those files become Media linked to the Source record in your Project?
> The files are the images from which the source record data has been extracted. I'm not sure how FH7 wants them linked.

Re: Does FH7 have a way of replacing characters in a text string?

Posted: 04 Apr 2023 21:52
by tatewise
To get an image to appear in FH Reports and Webpages it must be linked as a Media entity in much the same way as RM has Media entities.
e.g.
If you open an Individual record or Source record Property Box there is a Media tab for adding Media.
Those are Media records that can be seen in the Records Window Media tab and the Media Window.
Each such Media record is linked to a Media file by its folder and filename.
So it is that File link in the Media record that needs a suitably valid filename.

A popular strategy is to make the Source record Title the same as the Media record Title and compose the File name from the Media record Title by adjusting characters as necessary. There are existing plugins that do that.

However, since the file already exists it can be easily added to the Source record via its Media tab using the Add Media button.
The name of the file does not have to match the Media Title or Source Title. So I don't see any advantage of making the Source record Title format exactly match the Media filename.

Re: Does FH7 have a way of replacing characters in a text string?

Posted: 04 Apr 2023 23:44
by Gary_G
Thanks for the explanation, Mike.
With all the places to attach media, one wants to ask before going too far.

I just happen to find it easier to find image files, when the media filename matches the source name.
But I do understand what you mean.