PropertyWizard V1-8-2 gives you several ways to extract one piece of text from another. This post explains how to split a text like this into two pieces at the semicolon:
There are three steps:
- Find the position of the semicolon
- Extract the first part of the text
- Extract the second part of the text
In a real project, you do not need to do step 1 separately: I am just splitting it out as a separate step here to show you how the formulas work.
Character positions
PropertyWizard numbers the characters in a text starting at zero for the first character. In the example text, the characters are numbered like this:
character | E | : | 9 | . | 9 | ; | N | : | 1 | 0 | . | 8 |
number/index | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
Sometimes I call this the ‘number’ of the character, and sometimes the ‘index’ – both mean the same thing.
Find the semi-colon
The first step is to find the index of the semicolon character. We’ll use the instr() function to do this, using a formula like this:
instr(<text>, “;”)
You would put the name of your source parameter where I have written <text>. In this screenshot, I am using a source parameter that I’ve named DWD_Coordinate:
For a set of sample source values, this formula produces these results:
Extract the first part
The new leftstr() function is a good way to extract the first part of the text, because it extracts a specific number of characters from the start of a text string.
How many characters do we need? If the instr returns 4, there are 4 characters to the left of the semicolon – so we can just use the instr directly in the call to leftstr:
leftstr(<text>, instr(<text>, “;”))
Extract the second part
To extract the second part of the text, we have a choice of three functions:
- substr(<text>, <startIndex>, <count>)
- substr(<text>, <startIndex>)
- rightstr(<text>, count>)
Any of these could be made to work, but since the instr returns the index (character number) of the semicolon, the most straightforward choice is substr(<text>, <startIndex>).
What startIndex value do we need to use? We need to start at the character after the semicolon, so we can just add 1 to the value returned by the instr:
substr(<text>, 1 + instr(<text>, “;”))
Conclusion
So, that is a quick walk-through on splitting a text value at a particular character using the new functions from PropertyWizard 1-8-2.
You can download these formulas in a PropertyWizard xml file, and import them into your own projects – you will need to change the source and target properties to suit your projects.