JAVA代码:
public static String getCode128h(String strnum)
{
byte[] bs = {0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};
int length = strnum.length();
byte[] b = new byte[18+length];
b[0] = 0x1b;
b[1] = 0x64;
b[2] = 0x02;
b[3] = 0x1d;
b[4] = 0x48;
b[5] = 0x32;
b[6] = 0x1d;
b[7] = 0x68;
b[8] = 0x50;
b[9] = 0x1d;
b[10] = 0x77;
b[11] = 0x02;
b[12] = 0x1d;
b[13] = 0x6b;
b[14] = 0x49;//code128
b[15] = (byte)(length+2);
b[16] = 0x7b;
b[17] = 0x42;
for (int i = 0; i < length; i++){
String s = String.valueOf(strnum.charAt(i));
int index = Integer.parseInt(s);
b[18 + i] = bs[index];
}
String strcode = null;
try {
strcode = new String(b,"ISO-8859-1");
} catch (Exception e) {
e.printStackTrace();
}
return strcode;
}
转C#代码我是这样写的,但拼接到参数里就是乱码,导致请求失败- -、哪位大大能够帮忙看看是不是我的C#代码哪写错了?
public String getCode128h(String strnum)
{
byte[] bs = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39 };
int length = strnum.Length;
byte[] b = new byte[18 + length];
b[0] = 0x1b;
b[1] = 0x64;
b[2] = 0x02;
b[3] = 0x1d;
b[4] = 0x48;
b[5] = 0x32;
b[6] = 0x1d;
b[7] = 0x68;
b[8] = 0x50;
b[9] = 0x1d;
b[10] = 0x77;
b[11] = 0x02;
b[12] = 0x1d;
b[13] = 0x6b;
b[14] = 0x49;//code128
b[15] = (byte)(length + 2);
b[16] = 0x7b;
b[17] = 0x42;
for (int i = 0; i < length; i++)
{
string s = (CharAt(strnum,i)).ToString();
int index = Convert.ToInt32(s);
b[18 + i] = bs[index];
}
String strcode = null;
try
{
m.Text.Encoding.UTF8.GetString(b);//new String(b, "ISO-8859-1");
strcode = Encoding.GetEncoding("ISO-8859-1").GetString(b);
}
catch (Exception e)
{
}
return strcode;
}
public static string CharAt(string s,int index){
if((index >= s.Length)||(index<0))
return "";
return s.Substring(index,1);
}