Home > Net >  How to get a string of bytes?
How to get a string of bytes?

Time:10-07

Vs the first question is, do you have a can you tell me the number of bytes in a string of function?
The second problem is that in Chinese string, symbols, Numbers, whether all of two bytes in English?

CodePudding user response:

See with what specific account for how many bytes
Encoding UTF8. GetByteCount (" ")
UTF8 encoding, the other is similar

CodePudding user response:

This need into a byte array and then obtain coding length vary the length of the byte array, common UTF8 encoding
Var arr=Encoding. UTF8. GetBytes (STR)
Arr. The length is the number of bytes

CodePudding user response:

refer to the second floor 711 glaciers response:
this need into a byte array and then obtain coding length vary the length of the byte array, common UTF8 encoding
Var arr=Encoding. UTF8. GetBytes (STR)
Arr. The length is the number of bytes

Bosses have a problem!
 
String STR="123";
Var arr=Encoding. UTF8. GetBytes (STR);
Console. WriteLine (arr. Length);
Console.ReadKey();

Do you see it?
Why am I the output is the number of characters?

CodePudding user response:

reference 1st floor stherix response:
to see with what specific accounts for how many bytes
Encoding UTF8. GetByteCount (" ")
UTF8 encoding is such, and other similar

What is the general use of code?

CodePudding user response:

reference 1st floor stherix response:
to see with what specific accounts for how many bytes
Encoding UTF8. GetByteCount (" ")
UTF8 encoding is such, and other similar

, my bosses and output once he shows me a byte array, and then wrote him so, the result error this how to return a responsibility?
 
String STR="123";
Byte [] a Encoding UTF8. GetBytes (STR);
Console. WriteLine (a);
Console.ReadKey();

CodePudding user response:

Xuerueheng
reference 4 floor response:
Quote: refer to 1st floor stherix response:

See with what specific account for how many bytes
Encoding UTF8. GetByteCount (" ")
UTF8 encoding is such, and other similar

What is the general use of code?


Common UTF8, basic it is a kind of on the web, vs the editor to save the code file is also one of the
GBK/GB2312, this is Chinese Windows system default encoding
Unicode, the.net character/string is the code in the memory

CodePudding user response:

reference 5 floor xuerueheng reply:
Quote: refer to 1st floor stherix response:

See with what specific account for how many bytes
Encoding UTF8. GetByteCount (" ")
UTF8 encoding is such, and other similar

, my bosses and output once he shows me a byte array, and then wrote him so, the result error this how to return a responsibility?
 
String STR="123";
Byte [] a Encoding UTF8. GetBytes (STR);
Console. WriteLine (a);
Console.ReadKey();


Use GetByteCount can obtain the number of bytes, GetBytes will obtain the actual byte array

CodePudding user response:







?????????????????????????


So trouble?


On the regular (most compilers) :


One character of a byte


A string a few characters is a few bytes




ASCII:

1 byte characters in English and Chinese two bytes


UTF

A byte in English and Chinese three bytes


UniCode
Two bytes in English and Chinese character two bytes
  •  Tags:  
  • C#
  • Related