Stylesheet Development with PTC ALD > Adding PTC ALD Code to Stylesheet Source > Samples > Counters and Variables > Use PTC ALD Counters and Variables > String Counters
  
String Counters
Refer to the String counters chapter of the sample file: Arbortext-path/samples/ALD/CountersAndVariables/countersAndVariables.xml. The emphasis tags in the second paragraph each reference a different property set in the associated stylesheet, based on the value of the role attribute. The property sets in turn include PTC ALD source code edits to manipulate string counters. Access the source code for the property set by selecting it in the Property Sets list, and using the Edit > Edit Property Set Source > APP menu option.
Set the value of the string counter
The condition IF attribute “role” = “set” of the emphasis everywhere context references the StringCounterSet property set. This property sets the value of a string counter to the given text string. The relevant code in that property set is given below.
formatting.stringCounters[10] = " Hello Styler Users ";
Here you are accessing the numeric counter slot numbered 10, and setting its value to the string Hello Styler Users. As mentioned previously, string counters are accessed via the stringCounters property of the fFormatting object. The number in the square brackets is the counter slot you wish to use (from 10–99).
Output the value of the string counter
The condition IF attribute “role” = “get” of the emphasis everywhere context references the StringCounterDisplay property set. This property outputs the current value of the string counter. The relevant code in that property set is given below.
formatting.write(" [" + formatting.stringCounters[10] + "] ");
Here you are calling the write() method of the fFormatting object to output the value of the string counter slot numbered 10.
Note the inclusion of " [" + and + "] ". Syntax of this type adds the character displayed in quotes to the value of the counter when it is output. In this case the additional characters are [ and ] so the final output text will read [Hello Styler Users].