!replace … replace! function
This function is used inside values for commands (like paragraph or filename) to replace one string with another
Syntax:
!replace original string::string to replace::replace by string replace!
The replace function consists of three parts separated by :: characters,
The first part is the original string that have characters to replace
The second part is the string to search for in the original string
The third part is the string to replace the second part with.
Example:
!replace This is 100::100::500 replace!
The result is:
This is 500
The useful functionality here is that all parts can contain Block values.
Example:
!replace {Original Block}::{String To Be Replaced}::{String To Replace With} replace!
Real Example:
Add a block (named Ticket) that asks the user for a ticket no, which usually starts with trailing zeros
for example, the user enters 00001 as the Ticket no.
If it is required to add 1 to it and print it somewhere else in the document, then we use the math function in a paragraph as such
paragraph: !math {Ticket}+1 math!
but this will return 2 and not 00002
To rectify this, we use the replace function. Enter the following as the value to the paragraph command:
!replace {Ticket}::!math {Ticket} math!::replace!!math {Ticket}+1 math!
This will replace the string ‘1’ in ‘00001’ with nothing (nothing is entered between the last :: and the closing replace!), hence the replace function will return the 4 zeros only 0000 then the math function at the end will bring the value 2. The final result will be 00002
String ‘1’ is the result of !math {Ticket} math!
Another approach is to use a second block (let’s name it BlockNo) with paragraph and value !math {Ticket} math!
Then the paragraph command value would be:
!replace {Ticket}::{TicketNo} ::replace!!math {Ticket}+1 math!
Note: The second part can be a standard regex expression.
Example:
!replace {BlockName}::\d::# replace!
The above expression replaces all digits with # character.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article