日期:2014-05-20  浏览次数:20747 次

大家帮忙怎么实现固定报文长度
我的c语言是这样的:
struct   SNDTOMSGASC
{
        char   cardno[20];
        char   mobilephone[22];
        char   content[161];
        char   transtype[2+1];
        char   checkinfo[2+1];
        char   feeusertype[1+1];
        char   feetype[3];
        char   feecode[7];
        char   amount[12+1];
        char   response[2+1];
        char   reserve1[8];
        char   reserve2[8];
        char   reserve3[8];
}outmsg;

        memset(outmsg.cardno,   0,   sizeof(outmsg.cardno));
        strcpy(outmsg.mobilephone,   TeleNo);
        strcpy(outmsg.content,   Message);
        strcpy(outmsg.transtype,   "02 ");
        strcpy(outmsg.checkinfo,   "00 ");
        strcpy(outmsg.feeusertype, "0 ");
        strcpy(outmsg.feetype, "01 ");
        strcpy(outmsg.feecode, "000000 ");
        strcpy(outmsg.amount, "000000000000 ");
        strcpy(outmsg.response, "00 ");
        strcpy(outmsg.reserve1, "               ");
        strcpy(outmsg.reserve2, "               ");
        strcpy(outmsg.reserve3, "               ");
这里边都是报文,怎么用java也实现固定长度的报文呢?
            char[]   cardno   =   new   char[20];
            char[]   mobilephone=   new   char[22];
或者
            byte[]   cardno   =   new   byte[20]
或者
            String   s;
            s=s   +   cardno;
谢谢

------解决方案--------------------
java里面也可以定义定长的数组阿。
------解决方案--------------------
LZ为社么要定长?拼接报文吗~
StringBuilder string=new StringBuilder();
string.append(newString);
------解决方案--------------------
char[] cardno = new char[20];这样在java里不行么??
可以啊。其实java中的字符串就是一个字符数组。
------解决方案--------------------
up
------解决方案--------------------
楼主可以用byte[]数组来实现