Str. getbytes (). Length! in different environments! = Str. Length?
In the test environment, it is okay to determine whether there is a full angle. The results are different in the formal environment.
Both are UNIX systems, but the system languages are different.
Is there a way to make the running results consistent in different environments?
That is to say, the encoding to be used is the same.
The page is coded in UTF-8.
Str. getbytes ('utf-8'). length! = Str. Length,
You still need Str. getbytes ('unicode '). length! = Str. Length ().
Getbyte () uses the default encoding.
Use UTF-8 most insurance:
Str. getbytes ("UTF-8"). length! = Str. Length ();
There is a problem with Unicode. The following inequality will always be true regardless of the character.
Str. getbytes ("Unicode"). length! = Str. Length ();
In addition, str. getbytes (). length has different lengths in different environments.
Test:
Str. getbytes (). Length
In Windows XP, a full-width character is 2 characters in length;
In the liunx environment, a full-width character is 3 characters in length.
Solution:
Because it is in the Japanese operating system, the Code ms932 is added.
Str. getbytes ("ms932"). Length
In this way, the length of the two system environments is 2.