String aa = "134754481";
        String bb = "134754481";
      
       
        if( cc.equals(bb))
        {
           System.out.print("相等");  
        
        } 
        System.out.print(aa.length());
        System.out.print(bb.length());

解决方案 »

  1.   

    replaceAll
    public String replaceAll(String regex,
                             String replacement)
    Replaces each substring of this string that matches the given regular expression with the given replacement. 
    An invocation of this method of the form str.replaceAll(regex, repl) yields exactly the same result as the expression Pattern.compile(regex).matcher(str).replaceAll(repl)Parameters:
    regex - the regular expression to which this string is to be matched 
    Returns:
    The resulting String 
    Throws: 
    PatternSyntaxException - if the regular expression's syntax is invalid
    Since: 
    1.4 
    See Also:
    Pattern
      

  2.   

    public static String toFullWidth(String halfWidth) {
      StringBuffer buff = new StringBuffer(halfWidth.length());
      for (int i = 0; i < halfWidth.length(); i++) {
        char c = halfWidth.charAt(i) - '0' + '0';
        buff.append(c);
      }
      return buff.toString();
    }
      

  3.   

    sorry char c = (char) half.....没有用编译器写,直接在ie里面写的,应该不会有问题
      

  4.   

    public String wToF (String aW)
    {
    String [] tmp = new String [] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
    for (int i = 0; i <= 9; i ++)
    aW = aW.replaceAll (tmp [i], i + ""); return (aW); 
    }String aa = "134754481";
    String bb = "134754481";if( bb.equals(wToF (aa)))
    {
        System.out.print("相等");  
    }
      

  5.   

    1和1对应的anscii码差30(或31记不清楚了)
      

  6.   

    半角转全角
    半角1个字节:byte a = '1';
    全角2个字节:dst[0]=0xA3; 
                 dst[1]=(byte)(0x80+a)             System.out.println(new String(dst));  
      

  7.   

    先用下面的办法把字符转换成全角在比较
    String str = "123";
         String ret = "";
          for (int i = 0; i < str.length(); i++) {
            int j = str.charAt(i);
            if(j<256 && j>-1){              int temp = j + 65248;
               if (temp > 0)
                   ret += (char) temp;
               else
                   ret += (char) j;
            }else
               ret += (char) j;
          }
    System.out.println(str + "|" +ret);
      

  8.   

    kingfish(八百里秦川@龙城异客) 正解
      

  9.   

    说得很不明确。中文都是全角,没有必要转换。只有数字,字母是半角。我们当初做过转换。将全角和半角分别放在两个数组里。比如:a[10]="1,2,3,4,5,6,7,8,9,0"  b[20]="1,2,3,4,5,6,7,8,9,0"注意,b必须是20个字节。然后通过for 确定半角在a中的位置,比如半角2为a中的第二位,则在b中从第2*2-1=3位开始,读取b数组中的2个字符。则是全角的2
      

  10.   

    String .replaceAll(String regex,String replacement),还是这个比较容易。
      

  11.   

    说差30(或31)应该是胡说八道吧!
    查表?查什么表?Unicode表?
    根本就没有什么数字1,字符1。看看汇编吧。
    好像也用不上正则表达式吧?谁能给出一个精确的regex?
      

  12.   

    全角转换成半角 
     private static String DBC2SBC(String str) 
     {       String ret="";
        int k=0;
      for (int i = 0; i < str.length(); i++) {
       int j = str.charAt(i);
       if(i>0){
        k=str.charAt(i-1);
       }
       if(j==163){   
       continue;
       }else
       {
        if((j>=128)&&(k==163)){
         ret += (char) (j-128);
        }
        else
        {ret += (char) (j);
        }
       }
      }
      return ret;
      
     }
      

  13.   

    http://blog.csdn.net/sinkiangscorpio/archive/2005/06/14/394207.aspx
      

  14.   

    个人愚见:
    shine333(enihs) 的方法不能处理一个字符串中既有半角又有全角
    cuizm(射天狼)的方法,用了10次replaceAll,虽然可以达到目的,还是有点浪费,另外如果不知道aa,bb哪个中有全角,那就要用20次replaceAll:)
    //以下代码在ecplise下测试通过
    private String BanJiaotoQuanJiao(String strInput){
    byte[] aa = strInput.getBytes();
    byte[] bb = new byte[aa.length*2];
    int temp = 0;
    int j = 0;
    for (int i = 0 ; i<aa.length ; ++i ) {
    if (aa[i]  != -93) {
    bb[j] = -93;
    temp = aa[i] | 0x80;//加上高位1
    bb[j+1]= (byte)temp;
    j = j+2;  

    }
    byte[] result = new byte[j];
    System.arraycopy(bb,0,result,0,j);
    String strResult = new String(result);
    aa = null;
    bb = null;
    result = null;
    return strResult;
    }
    public static void  main(String [] args){
                      //全角半角混杂
    String aa = "1234567891";
                String bb = "134754481";
    String strResult = BanJiaotoQuanJiao(aa);
    System.out.println(strResult);
                      strResult = BanJiaotoQuanJiao(bb);
    System.out.println(strResult);
    }         
      

  15.   

    网上查了一些资料,是关于全角字节说明的,中午的时候写了一个功能类,可以把所有全角转化为半角,包括包括全角字符,全角空格 ,汉字默认不处理。import java.util.StringTokenizer;/**
     * @author chuayuan88 
     * 说明:该类实现把字符中的全角转化为半角,包括全角字符,全角空格.
     * 在windows中,中文和全角字符都占两个字节,并且使用了ascii chart 2 (codes 128?C255)。
     * 我们可以凭这一点来一个个检测用户输入的是否是中文和全角字符。
     * 实际上,全角字符的第一个字节总是被置为163,而第二个字节则是相同半角字符码加上128(包  * 括空格)。
     * 如半角a为65,则全角a则是163(第一个字节)、193(第二个字节,128+65)。 而对于中文来讲,*它的第一个字节被置为大于163,
     * (如'阿'为:176 162),我们可以在检测到中文时不进行转换。
     */
    public class EmptyLence {private static int b2i(byte n) {
    int m = n;
    if (n < 0) {
    m = n + 256;
    return m;
    }
    return m;
    }private static byte i2b(int n) {
    byte m = (byte) n;
    if (n > 127) {
    m = (byte) (n - 256);
    return m;
    }
    return m;
    }private static byte[] getOutputList(byte[] m) { //过滤byte数组中为0的元素
    int len = m.length;
    StringBuffer temp = new StringBuffer(1024);
    for (int i = 0; i < len - 1; i++) {
    if (m[i] != 0) {
    temp.append(m[i]);
    temp.append(",");
    }
    }
    temp.append(m[len - 1]);
    StringTokenizer st = new StringTokenizer(temp.toString(), ",");
    int total = st.countTokens();
    byte[] newList = new byte[total];
    for (int i = 0; i < total; i++) {
    newList[i] = (byte) Integer.parseInt(st.nextToken());
    }
    return newList;}public static void main(String[] args) {
    String oldStr = "abc def 中国队";
    int n = oldStr.getBytes().length; 
    byte[] strList = new byte[n + 1]; 
    for (int j = 0; j < n; j++) {
    strList[j] = oldStr.getBytes()[j];
    }
    byte[] newList = new byte[n];
    int c1, c2;
    for (int i = 0; i < newList.length; i++) {
    c1 = b2i(strList[i]);
    c2 = b2i(strList[i + 1]);if (c1 == 163) { //判断是否为全角字符
    newList[i] = i2b(c2 - 128);
    i++;
    continue;
    }if (c1 > 163) { //判断是否为汉字
    newList[i] = i2b(c1);
    newList[i + 1] = i2b(c2);
    i++;
    continue;
    }if ((c1 == 161) && (c2 == 161))//全角空格是个特例,另加处理
    {
    newList[i] = 32;
    i++;
    continue;
    }
    newList[i] = i2b(c1);}byte[] outputList = getOutputList(newList);
    System.out.println(new String(outputList));}}