Skip to content

Length and Size of String in Encoding - C# #153

Answered by christiannagel
ShervanN asked this question in Q&A
Discussion options

You must be logged in to vote

When you write the preamble to the console, you don't access the bytes returned from encoding.GetPreamble(). Instead, you access the converted bytes. The GetBytes method doesn't add a preamble.
You can add the preamble yourself - if you would like to use this. For single strings you don't really need to do this. It's useful to prefix a complete text which you store on disk or send across the network, so it can easily be accessed again - also on other platforms.

In Chapter 18, Files and Streams (section Analyzing Text File Encodings on page 497 you can read something about the different encodings and the reason for these byte order marks (BOM).

What you now get with ASCII is 4 bytes repres…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@ShervanN
Comment options

Comment options

You must be logged in to vote
1 reply
@ShervanN
Comment options

Answer selected by christiannagel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants