Does anyone know if the standard Java library (any version) provides a means of calculating the length of the binary encoding of a string (specifically UTF-8 in this case) w
You can loop thru the String:
/**
* Deprecated: doesn't support surrogate characters.
*/
@Deprecated
public int countUTF8Length(String str)
{
int count = 0;
for (int i = 0; i < str.length(); ++i)
{
char c = str.charAt(i);
if (c < 0x80)
{
count++;
} else if (c < 0x800)
{
count +=2;
} else
throw new UnsupportedOperationException("not implemented yet");
}
}
return count;
}