I have an Intermec PC43t barcode printer and i can't print greek characters. When i send greek characters for printing i have dots where the characters should be. When i print something in english i have the right result.
I send ZPL2 commands to Intermec printer (via Zsim).
Below are the commands.
^XA
^BY3
^FT430,80
^BCI,80,Y,N,N
^FD00001978^FS
^FT360,320^ADI,25,14^FD123457^FS
^FT140,320^ADI,25,14^FD1245^FS
^FT300,270^ADI,40,20^FD8794465^FS
^FT300,215^ADI,40,20^FD99999 / 99999^FS
^FT430,175^ADI,25,15^FD40125 - Ελληνικά - Greek ^FS
^XZ
Does someone know a solution?
Thank you
You could try with CIX parameter (Change International Font/Encoding), where X is number of encoding.
May be Zebra Code Page 1253 — Modern Greek Character Set ?
CI34 = Code page 1253
Example of usage:
^FB559,,,C,^FT30,106^A#N,23,31,TT0003M_^FH^CI17^F8^FD_text_^FS^CI0
This solution is not Unicode, but if your firmware supports it (x.14.x and higher according to the documentation) you can force the Greek windows-1253 codepage and append using the hex version of the 1253 code table for each character.
Note: Despite the name, windows-1253 does not require the Windows operating system to function with a Zebra printer.
// ^XA = Start of label
// ^XZ = End of label
// ^CF = Font size
// ^FO = X,Y position on label
// ^CI34 = Code Page 1253 - Zebra x.14.x fimware or higher only
// ^FH = Allow "_FF" style escaped hex characters
^XA
^CF0,60
^CI34^FO50,50^FH^FD - Theta: _C8 ^FS
^CI34^FO50,100^FH^FD - Lambda: _CB ^FS
^XZ
The disadvantage of this approach is a programmer will have to either:
Dynamically map each Greek character to a cp1253 equivalent before preparing the ZPL message, or...
Use a character encoding converter to map the UTF character to the cp1253 equivalent before sending. Many programming languages have built-in methods for doing this. Warning as these may appear as strange symbols in a terminal or output stream.
So, if the printer directly supports Unicode data, that is the ideal solution, but if it doesn't, cp1253 may be a viable option.
Following trsef's answer. This is a Java class that works for me. Might someone find it helpful and save some time:
public class GreekToHexZPL {
public String convertText(String newText) {
StringBuilder sBuilder = new StringBuilder();
for (int i = 0; i < newText.length(); i++) {
switch (newText.charAt(i)) {
case 'Α':
sBuilder.append("_C1");
break;
case 'Β':
sBuilder.append("_C2");
break;
case 'Γ':
sBuilder.append("_C3");
break;
case 'Δ':
sBuilder.append("_C4");
break;
case 'Ε':
sBuilder.append("_C5");
break;
case 'Ζ':
sBuilder.append("_C6");
break;
case 'Η':
sBuilder.append("_C7");
break;
case 'Θ':
sBuilder.append("_C8");
break;
case 'Ι':
sBuilder.append("_C9");
break;
case 'Κ':
sBuilder.append("_CA");
break;
case 'Λ':
sBuilder.append("_CB");
break;
case 'Μ':
sBuilder.append("_CC");
break;
case 'Ν':
sBuilder.append("_CD");
break;
case 'Ξ':
sBuilder.append("_CE");
break;
case 'Ο':
sBuilder.append("_CF");
break;
case 'Π':
sBuilder.append("_D0");
break;
case 'Ρ':
sBuilder.append("_D1");
break;
case 'Σ':
sBuilder.append("_D3");
break;
case 'Τ':
sBuilder.append("_D4");
break;
case 'Υ':
sBuilder.append("_D5");
break;
case 'Φ':
sBuilder.append("_D6");
break;
case 'Χ':
sBuilder.append("_D7");
break;
case 'Ψ':
sBuilder.append("_D8");
break;
case 'Ω':
sBuilder.append("_D9");
break;
case 'Ϊ':
sBuilder.append("_DA");
break;
case 'Ϋ':
sBuilder.append("_DB");
break;
case 'ά':
sBuilder.append("_DC");
break;
case 'έ':
sBuilder.append("_DD");
break;
case 'ή':
sBuilder.append("_DE");
break;
case 'ί':
sBuilder.append("_DF");
break;
case 'ΰ':
sBuilder.append("_E0");
break;
case 'α':
sBuilder.append("_E1");
break;
case 'β':
sBuilder.append("_E2");
break;
case 'γ':
sBuilder.append("_E3");
break;
case 'δ':
sBuilder.append("_E4");
break;
case 'ε':
sBuilder.append("_E5");
break;
case 'ζ':
sBuilder.append("_E6");
break;
case 'η':
sBuilder.append("_E7");
break;
case 'θ':
sBuilder.append("_E8");
break;
case 'ι':
sBuilder.append("_E9");
break;
case 'κ':
sBuilder.append("_EA");
break;
case 'λ':
sBuilder.append("_EB");
break;
case 'μ':
sBuilder.append("_EC");
break;
case 'ν':
sBuilder.append("_ED");
break;
case 'ξ':
sBuilder.append("_EE");
break;
case 'ο':
sBuilder.append("_EF");
break;
case 'π':
sBuilder.append("_F0");
break;
case 'ρ':
sBuilder.append("_F1");
break;
case 'ς':
sBuilder.append("_F2");
break;
case 'σ':
sBuilder.append("_F3");
break;
case 'τ':
sBuilder.append("_F4");
break;
case 'υ':
sBuilder.append("_F5");
break;
case 'φ':
sBuilder.append("_F6");
break;
case 'χ':
sBuilder.append("_F7");
break;
case 'ψ':
sBuilder.append("_F8");
break;
case 'ω':
sBuilder.append("_F9");
break;
case 'ϊ':
sBuilder.append("_FA");
break;
case 'ϋ':
sBuilder.append("_FB");
break;
case 'ό':
sBuilder.append("_FC");
break;
case 'ύ':
sBuilder.append("_FD");
break;
case 'ώ':
sBuilder.append("_FE");
break;
case 'Ά':
sBuilder.append("_Α2");
break;
case 'Έ':
sBuilder.append("_Β8");
break;
case 'Ή':
sBuilder.append("_Β9");
break;
case 'Ί':
sBuilder.append("_ΒA");
break;
case 'Ό':
sBuilder.append("_ΒC");
break;
case 'Ύ':
sBuilder.append("_ΒE");
break;
case 'Ώ':
sBuilder.append("_ΒF");
break;
case 'A':
sBuilder.append("_41");
break;
case 'a':
sBuilder.append("_61");
break;
case 'B':
sBuilder.append("_42");
break;
case 'b':
sBuilder.append("_62");
break;
case 'C':
sBuilder.append("_43");
break;
case 'c':
sBuilder.append("_63");
break;
case 'D':
sBuilder.append("_44");
break;
case 'd':
sBuilder.append("_64");
break;
case 'E':
sBuilder.append("_45");
break;
case 'e':
sBuilder.append("_65");
break;
case 'F':
sBuilder.append("_46");
break;
case 'f':
sBuilder.append("_66");
break;
case 'G':
sBuilder.append("_47");
break;
case 'g':
sBuilder.append("_67");
break;
case 'H':
sBuilder.append("_48");
break;
case 'h':
sBuilder.append("_68");
break;
case 'I':
sBuilder.append("_49");
break;
case 'i':
sBuilder.append("_69");
break;
case 'J':
sBuilder.append("_4A");
break;
case 'j':
sBuilder.append("_6A");
break;
case 'K':
sBuilder.append("_4B");
break;
case 'k':
sBuilder.append("_6B");
break;
case 'L':
sBuilder.append("_4C");
break;
case 'l':
sBuilder.append("_6C");
break;
case 'M':
sBuilder.append("_4D");
break;
case 'm':
sBuilder.append("_6D");
break;
case 'N':
sBuilder.append("_4E");
break;
case 'n':
sBuilder.append("_6E");
break;
case 'O':
sBuilder.append("_4F");
break;
case 'o':
sBuilder.append("_6F");
break;
case 'P':
sBuilder.append("_50");
break;
case 'p':
sBuilder.append("_70");
break;
case 'R':
sBuilder.append("_52");
break;
case 'r':
sBuilder.append("_72");
break;
case 'S':
sBuilder.append("_53");
break;
case 's':
sBuilder.append("_73");
break;
case 'T':
sBuilder.append("_54");
break;
case 't':
sBuilder.append("_74");
break;
case 'U':
sBuilder.append("_55");
break;
case 'u':
sBuilder.append("_75");
break;
case 'V':
sBuilder.append("_56");
break;
case 'v':
sBuilder.append("_76");
break;
case 'Y':
sBuilder.append("_59");
break;
case 'y':
sBuilder.append("_79");
break;
case 'Z':
sBuilder.append("_5A");
break;
case 'z':
sBuilder.append("_7A");
break;
case ' ':
sBuilder.append(" ");
break;
default:
sBuilder.append(newText.charAt(i));
break;
}
}
return sBuilder.toString();
}
}
Related
I want to know the major use cases with example will be great.
Where to use enum -> common example suppose you want to a show week days name “MONDAY – SUNDAY” in a dropdown menu at that time you know week days data is constant and will never change.
example:
enum day {
sunday,
monday,
tuesday,
wednesday,
thursday,
friday,
saturday,
}
void main() {
// assume you app user will select from Menu Item day
var selectedEnumDay = day.friday;
// Switch-case
switch(selectedEnumDay) {
case day.sunday: print("You selected sunday");
break;
case day.monday: print("You selected monday");
break;
case day.tuesday: print("You selected tuesday");
break;
case day.wednesday: print("You selected wednesday");
break;
case day.thursday: print("You selected thursday");
break;
case day.friday: print("You selected friday");
break;
case day.saturday: print("You selected saturday");
break;
}
}
Enum are a special type of class that allow creating a set of constant values associated with a particular type. [ 1 ]
Enums are great for representing a discrete set of states. [ 2 ]
one of simple example using enum is :
enum RequestState {success, error, notAsked, loading }
...
RequestState apiState = RequestState.notAsked;
Widget buildContaier() {
switch(apiState){
case apiState.loading:
return CircularProgressIndicator();
case apiState.success:
return ListView();
case apiState.error:
return Text("error fetch api");
default:
return Container();
}
I know in Swift I can do a simple Swift switch statement to compare computed values with a single variable:
let distanceTravelled = -145.1
switch distanceTravelled {
case _ where distanceTravelled < 15:
print("You travelled the right distance")
default:
print("Sad face")
}
But I want to be able to set up a matrix of comparisons using tuples, something like this:
let distanceTravelled = -145.1,
origin = 2
switch (origin, distanceTravelled) {
case (2, _ where distanceTravelled < 15):
print("You travelled the right distance")
default:
print("Sad face")
}
But this doesn't compile, complaining that expected ',' separator and expected expression in list of expressions.
Obviously this is syntactically incorrect, but shouldn't it work given that this works?
switch (2, -145.1) {
case (2, _):
print("You travelled the right distance")
default:
print("Sad face")
}
Aha! Found the answer in the good ol' Swift docs. I wasn't thinking of this in terms of the condition being a tuple.
switch (origin, distanceTravelled) {
case let (_, d) where d < 15:
print("You travelled the right distance")
default:
print("Sad face")
}
For my actual use case, this got a little weirder because I was comparing an enum property for origin, but it worked out:
let absOriginDistanceFromDefault = abs(defaultDividerPosition - viewDividerOrigin)
switch (splitViewOrigin, distanceTravelled) {
case let (.defaultPosition, d) where d < -100:
return .shouldMoveToTopView
case let (.defaultPosition, d) where d > 100:
return .shouldMoveToBottomView
case (.topView, _) where currentDividerPosition - defaultDividerPosition < -100:
return .shouldMoveToBottomView
case (.topView, _) where abs(distanceTravelled) > absOriginDistanceFromDefault * 0.5 && currentDividerPosition < self.view.bounds.height:
return .shouldMoveToDefaultPosition
case (.bottomView, _) where currentDividerPosition - defaultDividerPosition > 100:
return .shouldMoveToTopView
case (.bottomView, _) where abs(distanceTravelled) > absOriginDistanceFromDefault * 0.3 && currentDividerPosition > 0:
return .shouldMoveToDefaultPosition
default:
return .shouldReturnToOrigin
}
And oddly enough, in simplifying it further, it turns out I don't even need to declare variables in the first two checks at all:
let absOriginDistanceFromDefault = abs(defaultDividerPosition - viewDividerOrigin)
switch (splitViewOrigin, distanceTravelled) {
case (.defaultPosition, _) where distanceTravelled < -100,
(.bottomView, _) where currentDividerPosition - defaultDividerPosition > 100:
return .shouldMoveToTopView
case (.defaultPosition, _) where distanceTravelled > 100,
(.topView, _) where currentDividerPosition - defaultDividerPosition < -100:
return .shouldMoveToBottomView
case (.topView, _) where abs(distanceTravelled) > absOriginDistanceFromDefault * 0.5 && currentDividerPosition < maxHeight,
(.bottomView, _) where abs(distanceTravelled) > absOriginDistanceFromDefault * 0.3 && currentDividerPosition > 0:
return .shouldMoveToDefaultPosition
default:
return .shouldReturnToOrigin
}
Probably a basic question but I would like to reduce some code using multiple arguments on switch case statements. Possible? Correct syntax?
switch (myInteger){
case (1): //here I would like to apply multiple arguments as case (1 || 3 || 5)
<#statements#>
break;
case (2):
<#statements#>
break;
default:
break;
You can use multiple cases right below each other.
switch (myInteger) {
case 1:
case 3:
case 5:
// statements
break;
case 2:
// statements
break;
default:
// statements
break;
}
case 1:
case 3:
case 5:
statements;
break;
case 2:
statements;
break;
default:
break;
For Swift 3 there is a modification that I would like to mention
switch some value to consider {
case 1: //single argument
print("ABC")
case 2,3: // multiple arguments
print("KLM")
default:
print("XYZ")
}
Hope it helps you. Thanks
Switch case must declare inside the main method
SYNTAX
Switch (variable r expression)
{
Case 1 :
Body ;
Break
Case 2 :
Body;
Break;
Default :
Body ;
Break;
}
-(IBAction)changeSegmentDistance:(UISegmentedControl *)sender{
// refineDistance=sender;
switch ([refineDistance selectedSegmentIndex]) {
case 0:
valueString=5;
NSLog(#"value String %d",valueString);
break;
case 1:
valueString=10;
NSLog(#"value Stringaaaa %d",valueString);
case 2:
valueString=15;
NSLog(#"value String %d",valueString);
break;
case 3:
valueString=16;
NSLog(#"value String %d",valueString);
break;
default:
break;
}
}
When i running application and printing on Console
using NSLog...
when i select 0 its printing 5...
when i selected 1 its printing 10 and 15
when i selected 2 its printing 15
when i selected 3 its printed 16..
I dont know why its printing 10 and 15 when i selected 2nd.
You're missing a "break;" at the end of your "case 1" statement block. As such, execution is continuting into the next case statement.
You are missing a break for case 1.
Can it be done in a better way
public static EnumFactorType GetFactorEnum(string str)
{
Standardization e = new Standardization();
switch (str.ToLower())
{
case "beta":
e.FactorType = EnumFactorType.BETA;
break;
case "bkp":
e.FactorType = EnumFactorType.BOOK_TO_PRICE;
break;
case "yld":
e.FactorType = EnumFactorType.DIVIDEND_YIELD;
break;
case "growth":
e.FactorType = EnumFactorType.GROWTH;
break;
case "mean":
e.FactorType = EnumFactorType.MARKET_CAP;
break;
case "momentum":
e.FactorType = EnumFactorType.MOMENTUM;
break;
case "size":
e.FactorType = EnumFactorType.SIZE;
break;
case "stat_fact1":
e.FactorType = EnumFactorType.STAT_FACT_1;
break;
case "stat_fact2":
e.FactorType = EnumFactorType.STAT_FACT_2;
break;
case "value":
e.FactorType = EnumFactorType.VALUE;
break;
}
return e.FactorType;
}
If I create a Static class(say Constatant) and declare variable like
public static string BETA= "beta";
and then if I try to put that in the Case expression like
Case Constants.BETA : e.FactorType = EnumFactorType.BETA;
break;
then the compiler will report error.(quite expected)
So is there any other way?(I canot change the switch statement)
Using C#3.0
Thanks
You could define a Dictionary<string, EnumFactorType> as a "mapping" and use that instead. It's essentially the same logic but can be a bit more readable.
First, the mapping object:
private Dictionary<string, EnumFactorType> _mapping = new Dictionary<string, EnumFactorType>
{
{ "beta", EnumFactorType.BETA },
{ "bkp", EnumFactorType.BOOK_TO_PRICE },
// etc
}
Then in your method:
e.FactorType = _mapping[str.ToLower()];
You may want to call _mapping.ContainsKey(str) first just to be sure the mapping exists.
Use:
public const string BETA = "beta";
Works fine. The way you declared it, it is a variable. Variables are not allowed in case expressions. By using the const keyword, you're telling the compiler it's in fact a constant, as your class name suggests.
What do you mean by "I cannot change the switch statement"? With a sufficiently large amount of possibilities, I would consider using a Dictionary. Mind you, this would mostly be for readability and maintainability, not performance. With a Dictionary, it would be easier to do a reverse conversion for example, as you can construct a reverse dictionary from the same data.
Using a dictionary, it would look something like this:
private static readonly Dictionary<string, EnumFactorType> _factorTypeMap =
new Dictionary<string, EnumFactorType>(StringComparer.InvariantCultureIgnoreCase)
{
{ "beta", EnumFactorType.BETA },
{ "bkp", EnumFactorType.BOOK_TO_PRICE },
// etc. You can still use strings constants here instead of literals.
};
Then in your method:
EnumFactorType factorType;
if (_factorTypeMap.TryGetValue(str, out factorType))
{
e.FactorType = factorType;
}
else
{
throw new Exception("Unexpected value, bla bla");
}
If you're certain the value exists, it's simpler:
e.FactorType = _factorTypeMap[str];
Creating a reverse dictionary is a one-liner, displayed here on two lines :)
Dictionary<EnumFactorType, string> _factorTypeReverseMap =
_factorTypeMap.ToDictionary(kvp => kvp.Value, kvp => kvp.Key);
The strings used in a switch have to be constant, so if you declare a constant instead of a variable, you can use it in the switch:
public const string BETA = "beta";
If you don't want the strings to be constant, so that you can change them while the program is running, you can't use a switch. Then you could use a Dictionary<string, EnumFactorType> to look up the values to get similar performance as a switch.