Question

I am maintaining a program that outputs ZPL to a label printer. Today, the character sequence ~Ja came in as part of a string to be printed, which is ZPL's "cancel all" command. Needless to say, the label did not print.

Is there an easy way in ZPL to escape a tilde?

Was it helpful?

Solution

You can use ~CT or ^CT to change the tilde control character to any other ASCII character, and then you can print tildes normally. However, the new control character won't be printable. This is probably going to be quite a hassle to maintain.

An example changing the control command prefix to +, taken from page 165 of the ZPL II programming guide:

^XA
^CT+
^XZ
+HS

If your string is represented as field data with ^FD, ^FV, or ^SN, you can use ^FH to encode the tilde in the string with its hex value, 7E.

An example, taken from page 192 of the ZPL II programming guide:

^XA
^FO100,100
^AD^FH
^FDTilde _7e used for HEX^FS
^XZ

Output:

Tilde ~ used for HEX

OTHER TIPS

~ can be printed by replacing to \7E

It seeems like replacing these three characters will allow any key on the keyboard to print fine. I figured this out using ZebraDesigner, printing to a file and seeing what characters they escape.

\ to \1F - do this first or it will break the two below

~ to \7E

^ to \5E

Here is the code in C#

private static string escapeChars(string working)
{
working = working.Replace(@"\", @"\1F");
working = working.Replace(@"~", @"\7E");
working = working.Replace(@"^", @"\5E");
return working;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top