How to print a double quote using a Zebra printer with EPL?

1.6k views Asked by At

In Java, I want to print a label with a String as the input:

 String command
            = "N\n"
            + "A50,5,0,1,2,2,N,\"" + name + "\"\
            + "P1\n";    

But when the input (name) has a double quote character ("), it is blank and prints nothing. I have tried using the replace function:

name.replace('"', '\u0022');          

but it doesn't work. I want that double quote printed in label, how can I do this?

2

There are 2 answers

0
SMA On

Couple of points:

  • replace method returns back string after replacing so you should expect something like:

    command = command.replace...
    
  • quote has special meaning and hence needs to be escaped in Java. You need the following:

    name = name.replace("\"", "");
    String command
        = "N\n"
        + "A50,5,0,1,2,2,N,\"" + name + "\""
        + "P1\n"; 
    System.out.println(command);
    
1
Michael Kosak On

Sending the " character in the text field of the EPL string makes the EPL code think it is the end of the string you are trying to print.

So, if you want to send(and print) "hello" you have to put a backslash before each " character and send \"hello\"

You also have to do that for backslashes.

So, your (EPL)output to the printer would have quotes to begin and end the string, and \" to print the quote characters WITHIN the string :

A30,210,0,4,1,1,N,"\"hello\""\n

Also remember you have to escape to characters to build a c# string so in c# it would look like this: outputEPLStr += "A30,210,0,4,1,1,N,\"\\"hello\\"\"\n";

[which contains 6 escaped characters]