13.4.2.3. Topic Name Manipulation

It is sometimes necessary to modify topic names by extracting or deleting parts of the topic path. The following methods are available on any string variable.

Extract(start, count, splitChar = "/") Returns count number of topic path elements starting at start. Start can be a number from 0 to the number of path segments in the topic - 1. If start is negative then it will count from the last segment backward, where -1 is the last segment. If the specified count of segments is larger than the actual count then all segments from start will be returned. If splitChar is provided, the path elements will be determined by splitting the string on that character. For example:

var myTopic = "plant1/device1/pump1";
myTopic.Extract(1,1)   -->  "device1"
myTopic.Extract(-1,1)   -->  "pump1"
myTopic.Extract(0,2)   -->  "plant1/device1"

Delete(start, count, splitChar = "/") Returns the topic with count segments deleted starting at start. Start can be a number from 0 to the number of path segments in the topic - 1. If start is negative then it will count from the last segment backward, where -1 is the last segment. If the specified count of segments is larger than the actual count then all segments from start will be deleted. If splitChar is provided, the path elements will be determined by splitting the string on that character. For example:

var myTopic = "plant1/device1/pump1";
myTopic.Delete (1,1)   -->  "plant1/pump1"
myTopic.Delete (-1,1)   -->  "plant1/device1"
myTopic.Delete (0,2)   -->  "pump1"

Append(string, splitChar = "/") Appends two topic paths together, taking care that exactly one separator exists between the two paths. If splitChar is provided, it is used as the separator between the two paths. For example:

var myTopic = "plant1/device1/pump1";
myTopic.Append("pressure")   -->  "plant1/device1/pump1/pressure"