I do not believe Java has a standard method for this in the standard library, but you could implement yours :


public int byte_length(String s) { int numchars = s.length(); int numbytes = 0;

    for (int i = 0 ; i < numchars ; i++) {
      int c = s.charAt(i);
      if ((c >= 0x0001) && (c <= 0x007F)) numbytes++;
      else if (c > 0x07FF) numbytes += 3;
      else numbytes += 2;
    }

    return numbytes;
}


I have no idea if it would be faster than your current method though, but it should be more memory-efficient at least.



--cedricv

_______________________________________________
jdev mailing list
[EMAIL PROTECTED]
https://jabberstudio.org/mailman/listinfo/jdev

Reply via email to