How to split text at a character using PropertyWizard for Revit

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:

E:9.9;N:10.8

There are three steps:

  1. Find the position of the semicolon
  2. Extract the first part of the text
  3. 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:

characterE:9.9;N:10.8
number/index01234567891011

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:

PropertyWizard Formula window showing a formula for the category 'Columns', Target Property is 'DWD_SemicolonPosition' and the Formula text is 'instr(DWD_Coordinate, ";")'

For a set of sample source values, this formula produces these results:

Screenshot of a Revit Column Schedule showing two columns: DWD_Coordinate and DWD_SemicolonPosition

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>, “;”))

PropertyWizard Formula window showing a formula for the category 'Columns', Target Property is 'DWD_Eastings' and the Formula text is 'leftstr(DWD_Coordinate, instr(DWD_Coordinate, ";"))'
Screenshot of a Revit Column Schedule showing three columns: DWD_Coordinate, DWD_SemicolonPosition and DWD_Eastings

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>, “;”))

PropertyWizard Formula window showing a formula for the category 'Columns', Target Property is 'DWD_Northings' and the Formula text is 'substr(DWD_Coordinate, 1+ instr(DWD_Coordinate, ";"))'
Screenshot of a Revit Column Schedule showing four columns: DWD_Coordinate, DWD_SemicolonPosition, DWD_Eastings and DWD_Northings

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.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.