
 /**
/**
 * 按照指定长度将字符串进行分割,中文字符算2个长度
     * 按照指定长度将字符串进行分割,中文字符算2个长度
 * @param str 字符串
     * @param str 字符串
 * @param length 指定长度
     * @param length 指定长度
 * @return 如果字符串长度超出指定长度
     * @return 如果字符串长度超出指定长度
 * ,则将字符串分成2个部分,分别装在map中
     * ,则将字符串分成2个部分,分别装在map中
 */
     */

 public static Map getStr(String str, int length) {
    public static Map getStr(String str, int length) {
 HashMap hashMap = new HashMap();
        HashMap hashMap = new HashMap();
 String addr1 = "";
        String addr1 = "";
 String addr2 = "";
        String addr2 = "";

 byte tmpBytes[] = str.getBytes();
        byte tmpBytes[] = str.getBytes();
 int iByteLen = tmpBytes.length;
        int iByteLen = tmpBytes.length;

 if (iByteLen > length) {
        if (iByteLen > length) {
 int iLen = 0;
            int iLen = 0;

 for (int i = 0; i < length; i++) {
            for (int i = 0; i < length; i++) {

 if ((tmpBytes[i] & 0xFF) > 0x80) {
                if ((tmpBytes[i] & 0xFF) > 0x80) {
 iLen += 2;
                    iLen += 2;
 i++;
                    i++;
 continue;
                    continue;

 } else {
                } else {
 iLen += 1;
                    iLen += 1;
 continue;
                    continue;
 }
                }
 }
            }

 addr1 = new String(tmpBytes, 0, iLen);
            addr1 = new String(tmpBytes, 0, iLen);
 addr2 = new String(tmpBytes, iLen, iByteLen - iLen);
            addr2 = new String(tmpBytes, iLen, iByteLen - iLen);

 } else {
        } else {
 addr1 = str;
            addr1 = str;
 }
        }
 hashMap.put(new Integer(1), addr1);
        hashMap.put(new Integer(1), addr1);
 hashMap.put(new Integer(2), addr2);
        hashMap.put(new Integer(2), addr2);
 return hashMap;
        return hashMap;
 }
    }

0x80等于十进制的128,Turbo C中规定对ASCII码值大于0x80的字符将被认为是负数。
	
posted on 2009-09-22 22:32 
xrzp 阅读(2168) 
评论(1)  编辑  收藏  所属分类: 
JAVA