Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
I need CHR(10) in C#!
Message
De
09/01/2013 03:32:03
 
 
À
08/01/2013 19:10:18
Joel Leach
Memorial Business Systems, Inc.
Tennessie, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 5.0
OS:
Windows 7
Divers
Thread ID:
01561827
Message ID:
01561850
Vues:
57
A string is composed of characters, think of it as a character array. Internally a char is represented in Unicode (UTF-16) and occupies 2 bytes

C# is not converting it to '\n', it just displays it as '\n'

Also, bear in mind that in C#, a character is kept in UTF-16 format http://en.wikipedia.org/wiki/UTF-16/UCS-2

If the chars are later stored to say a text file, they are converted to a sequence of bytes using an Encodig http://msdn.microsoft.com/en-us/library/system.text.encoding.aspx

A char can occupy 1, 2, 3 or 4 bytes depending on (1) The encoding and (2) the char itself

Encrypting and Decrypting are never done on chars, but always on bytes

Consider using bytes if possible



>Here's my scenario: I am storing a small number as a single character in a string. If that number happens to be 10, C# is converting it to "\n". I imagine I will run into the problem with other escape codes as well. I really need CHR(10) to be stored in the string, not "\n". I've tried Convert.ToChar(myint), (char)myint, and even went so far as to use VisualBasic.Strings.Chr(), but it always comes back as "\n" in the string. The string is later encrypted, and that's where it is really messing things up. Is there anyway to "escape the escape" and prevent this from happening?
>
>Thanks.
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform