How to Use a String Replacement Script
Description
The following is an example of a string replacement script developed to allow the passing of a FNC1() character in a .pas or .xml data file. This concept can be applied to other scenarios where character sequences in the data from the input file is not allowed.
How to use a label script to replace a string or character
The following procedure replaces a string or character with another string or character using a label script. This also allows passing of data that is normally not allowed in an .xml file format.
- Set up a scripting field, input field, and a fixed field containing a formula with the replacement character ('FNC1 ()' as shown in the following example).
- Copy the sample script below into a text editor.
- Modify the sample script, using the names of the actual fields on your label.
- Copy the modified script into the scripting field data source window.
For an example, refer to the attached sample label fnc1 replace.lwl.
//Script allows customer to pass FNC1() character as data for barcode using proxy [FNC1]. Can be modified to allow any formula function character.
var input = String(label.fields.field.(@name == 'input_barcode').@data);
var fnc1 = String(label.fields.field.(@name == 'F1').@data);
var strReplaceAll = input;
var intIndexOfMatch = strReplaceAll.indexOf( "[FNC1]" );
// Loop over the string value replacing out each matching substring.
while (intIndexOfMatch != -1)
{
// Relace out the current instance.
strReplaceAll = strReplaceAll.replace( "[FNC1]", fnc1 )
// Get the index of any next matching substring.
intIndexOfMatch = strReplaceAll.indexOf( "[FNC1]" );
}
label.fields.field.(@name == 'input_barcode').@data = strReplaceAll;
Article Number
2017103
Versions
Loftware Label A label is a design area on the computer screen where a label format is created or edited. Manager / Loftware Print Server versions 9.5.2.0 - 11.1
Environment
Any supported LPS Family product environment