Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to encode strings like edit does in C#?
    text
    copied!<p>I am writing C# application that need to print data to POS STAR printer using RawPrinterHelper.</p> <p>My printing works fine except when I sending characters like ŽĆČĐŠ. Then I get wrong data printed out.</p> <p>Until now my research give me following results.</p> <p>If I in PowerShell open good old edit and in txt file write my characters (ŽĆČĐŠ) and send that to printer I get print out as I wish</p> <p>I can't that repeat using Notepad</p> <p>How I can in C# encode my sting to looks like that one from command prompt (EIDTor). So when I send data to printer it print Desire fonts as it looks like in Windows environment.</p> <p>I did also try to print using Star driver and their C# sample for sending data directly to printer but without success.</p> <h1>EDIT:</h1> <hr> <p>I did it, and for others Who in generally have troubles printing directly on Star printers using C# here is code for sample app from <a href="http://www.starasia.com/tsp650driverdownload.asp" rel="nofollow noreferrer">Star IO Programming Tool</a> for using their driver.</p> <pre><code>using System; using System.Text; using StarMicronics.StarIO; // added as a reference from the "Dependencies" directory // requires StarIOPort.dll, which is copied to the output directory by the Post-Build event namespace TestEnkodera { class Program { static void Main(string[] args) { string portName = "LPT1"; string portSettings = string.Empty; string print = string.Empty; //Select code page //Decimal 27 29 116 n print += string.Format("{0}{1}{2}{3}{4}", (char)27, (char)29, (char)116, (char)5, Environment.NewLine); print += "Đ Š Ž Ć Č ž ć č ć \n"; IPort port = null; port = StarMicronics.StarIO.Factory.I.GetPort(portName, portSettings, 10 * 1000); //byte[] command = ASCIIEncoding.ASCII.GetBytes(print); //This was orginal code provided by STAR Encoding ec = Encoding.GetEncoding(852); //Here is way to set CODEPAGE to match with printer CODE PAGE byte[] command = ec.GetBytes(print); uint totalSizeCommunicated = WritePortHelper(port, command); StarMicronics.StarIO.Factory.I.ReleasePort(port); Console.ReadKey(); } private static uint WritePortHelper(IPort port, byte[] writeBuffer) { uint zeroProgressOccurances = 0; uint totalSizeCommunicated = 0; while ((totalSizeCommunicated &lt; writeBuffer.Length) &amp;&amp; (zeroProgressOccurances &lt; 2)) // adjust zeroProgressOccurances as needed { uint sizeCommunicated = port.WritePort(writeBuffer, totalSizeCommunicated, (uint)writeBuffer.Length - totalSizeCommunicated); if (sizeCommunicated == 0) { zeroProgressOccurances++; } else { totalSizeCommunicated += sizeCommunicated; zeroProgressOccurances = 0; } } return totalSizeCommunicated; } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload