Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Encoding question
Message
De
11/11/2013 04:59:28
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01587700
Message ID:
01587719
Vues:
56
This message has been marked as the solution to the initial question of the thread.
>Why does C# char = (char)134 return different value character than VFP char(134)?
>
>UPDATE. I understand why but have not found the way to resolve my issue. I need to get a character (in .NET program) (for number 134 or higher) that match exactly the character that VFP gets when using char(134) and such.
>Any suggestion, please let me know. Except I cannot change the VFP code.


Since .net uses UTF-16 to store a char ( one char = 2 bytes ), you do not encode chars

When chars are stored to a file, they are first converted to a sequence of bytes (1, 2, 3 or 4 depending on the char and the encoding utf8, utf16, single byte char set, double byte chars set) and the byte sequence is written to the file
This means that a file does not contain chars, but bytes

You convert the chars to a byte array first, using an encoding, then encode the byte array

Supposing your code page in vfp is 1252
		internal static void Go()
		{
			// from byte to string
			byte[] src = new byte[] { 134 };
			string p = Encoding.GetEncoding(1252).GetString(src);

			// from string to bytes
			string s = "†"; // chr(134) in 1252 codepage

			byte[] bytes = Encoding.GetEncoding(1252).GetBytes(s);
			
		}
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform