c # bytes of the string

1.byte [] bytestr = System.Text.Encoding.Default.GetBytes (str); in this way can lead to inconsistencies length mobile platforms and PC computing platform, not recommended

2. using Unicode character code table, Unicode characters encoded interval: 0x4E00 → 0x9FA5

              int charNum = 0; // count byte-digit
			char [] _charArray = str.ToCharArray ();
			for (int i = 0; i < _charArray.Length; i++)
			{
				char _eachChar = _charArray [i];
				if (_eachChar> = 0x4e00 && _eachChar <= 0x9fa5) // determined Chinese character
					charnum + = 2;
				else 
					charnum + = 1;
			}

  

Guess you like

Origin www.cnblogs.com/wang-jin-fu/p/11795077.html