Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Encoding question
Message
 
 
À
11/11/2013 09:53:10
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:
01587745
Vues:
20
>>>>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);
>>>			
>>>		}
>>>
>>
>>Thank you and Viv for your messages. I understand - in general - about character sets and encoding. But still cannot seem to grasp how to apply it to my case. Let me describe what I am doing:
>>
>>In SQL Server database there is a table UserPasswords with column Password char(10) (not it is not nchar). The entry in this field column comes from VFP program. For example, when user creates password "123" the string "123 " (padded to 10 char) is converted to various high-position ASCII characters (above 128). The space in the password entry is converted (not always but often) to char(134) (which looks like you showed above, dagger, or cross).
>>
>>User in .NET app enters his/her password. Say he/she enters "123" and I am trying to convert (using my VFP-method) the string "123 " (padded to 10) into "encoded" string and then do the following SQL Select:
>>
>>
>>select * from UserPasswords where Password = "' + cEncodedPassword + "'"
>>
>>
>>The problem is that when I try to "encode" the string "123 " to a string (in .NET code) that would match VFP-type, it won't work. Because when encoding routine needs to set value of char(134) into the string, it does not at all match the VFP char(134).
>>
>>I realize that I should change how the password string is encoded in VFP but cannot since it is already used by millions (I wish :) customers.
>>
>>Any suggestions?
>
>I see you have this working but it occurred to me that it might be possible to do this in TSQL using CONVERT/COLLATE. But my SQL knowledge is so limited I'm not sure exactly how you'd do it :-{

Great minds <g>. I was looking at this last night also, Googling for making TSQL to do the conversion. But I was tired and my mind was not working. So I decided to look at it today. But now that you and Gregory found an easier solution, I will leave it at that.
I have to finish this Asp.NET applicaiton by next week or the following at the latest. So I have very little time to experiment.
Thank you.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform