If you are new to variables, you may want to read Introduction to Photo Mechanic Variables first. 


In programming, a "string" is a series of text characters. Many Photo Mechanic variables contain data in the form of strings, but sometimes you may want to filter out part of that text in order to fill out another metadata field. 

Substring extraction can be used to ‘extract’ a range of characters from an image variable so they can be used like normal variables in other fields throughout Photo Mechanic.

The format is: {variable:index,count:conversion} or {variable:index:conversion}

In either case, <:conversion> is optional.

<index> Sets the point in the string at which the operation starts - zero (0) will include all characters, 1 will ignore the first character, etc. This value can be positive or negative. Negative numbers count back from the end of the string, positive numbers count from the beginning.

<count> to extract <count> characters from <index>. <count> may be positive or negative. If <count> is negative then it trims off |<count>| characters from the end of the string. <count> may also be omitted altogether which indicates extracting the substring from <index> position to the end of the string. <conversion> may be one of the following types or may be omitted altogether:

“lc” perform lower-case conversion of all applicable characters
“UC” perform upper-case conversion of all applicable characters
“PC” perform Proper Name case conversion

Here are some examples:

Let’s say we have a file named DSC_1234.JPG

So the variable for {filename} would yield DSC_1234.JPG and {filenamebase} would be DSC_1234

Then to extract substrings from this:

{filenamebase:0,3} yields: DSC
{filenamebase:-4,4} yields: 1234
{filenamebase:-4} yields: 1234
{filenamebase:2,3} yields: C_1
{filenamebase:0:lc} yields: dsc_1234
{filenamebase:0:PC} yields: Dsc_1234
{filename:0,-4} yields: DSC_1234