Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# ASCII or Unicode

Tags:

c#

unicode

ascii

hi im a beginner in programming and network development. i have a question regarding ASCII and Unicode encoding.

in msdn and other web examples do the following:

byte[] byteData = Encoding.ASCII.GetBytes(data);

is this because these code samples are old? shouldn't it be:

byte[] byteData = Encoding.Unicode.GetBytes(data);

thanks for your input!

like image 685
iTEgg Avatar asked Jan 11 '10 14:01

iTEgg


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C full form?

Full form of C is “COMPILE”. One thing which was missing in C language was further added to C++ that is 'the concept of CLASSES'.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

What are basics of C?

It was mainly developed as a system programming language to write an operating system. The main features of the C language include low-level memory access, a simple set of keywords, and a clean style, these features make C language suitable for system programmings like an operating system or compiler development.


1 Answers

It depends - do you want the result to be in ASCII or UTF-16? Each is wrong when you want the other.

If you're talking some network protocol, you must find out which character encoding is expected by the protocol. Use the wrong encoding, and Bad Things Will Happen.

Of course ASCII has massive restrictions - it's very English-based (Latin characters only, no accents) but it's correct for some protocols. Others may use UTF-16 (Encoding.Unicode), UTF-8 or other encodings... or they'll let you specify the encoding yourself within the protocol.

like image 118
Jon Skeet Avatar answered Sep 19 '22 07:09

Jon Skeet