@tsolignani : This is most likely caused by the length() only count chars, while whatsapp or any other app limit the "chars" using byte storage. Non ASCII char usually use 2-4 bytes in one char. Example Japanese char usually use 3 bytes, emoji use 4 bytes. This is counted as 1 char only when using length().
I am still finding ways to calculate the real byte count. Have tried several java code and can't find a working one.
So far I use workaround code, using encodeURL(), find the non ASCII (and some symbol) using find(). Then use simple math to find the real length.
Code: Select all
status = "Hello ありがとう";
len = length(status); //11 chars, but wrong
//step by step
encode = encodeURL(status); //encode the space and japanese char
lenencode = length(encode); //total length of each encoded byte becomes 3, give 53
percent = length(findAll(encode, '%[0-9A-F]{2}')); //find the number of %xx encoded
reallen = lenencode - 2 * percent; //subtract by twice of that number
Hello = 5 chars, space = 1 char, ありがとう = 5 chars. Total is 11 chars, according to length(). However the byte used is not 11 byte.
encodeURL() and we get Hello%20%E3%81%82%E3%82%8A%E3%81%8C%E3%81%A8%E3%81%86
Which is total 53 chars. Space is now %20, become 3 chars (thrice). Each japanese char now become 9 chars, but it is actually 3 bytes only (since each %xx represent 1 byte). So we know that each encoded char expanded 3 times.
We find all the encoded char and count the occurance, result is 16 byte. 1 from space, 3 byte each from 5 japanese chars.
Since we need count the byte size only, we substract twice the length of the encoded char occurance, give us the real byte size = 21
Hello = 5 byte
space = 1 byte
ありがとう = 15 byte
I don't know how Whatsapp count the max status char limit, but maybe it count every byte used. Try this and see if you can post more than 700 byte. Adding emoji is one way to added up the byte used.
If you are OK with code above , then this is the single line version.
Code: Select all
status = "Hello ありがとう";
//single line version
reallen = length(encodeURL(status)) - 2 * length(findAll(encodeURL(status), '%[0-9A-F]{2}'));