>>>>>>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);
>>>>>
>>>>> }
>>>>>
>>>>
>>>>I re-read your code example and I see the solution there for me. Thank you!
>>>
>>>Good because I did not understand your first reply
>>
>>To clarify: in .NET when my code converts space (char(32) to an 'encrypted character' the logic is:
>>1. Get the ASCII number of this character (empty space). Which I can do as you suggested:
>>
>> byte[] bytes = Encoding.GetEncoding(1252).GetBytes(" ");
>>
>>2. Add 102 to the resulting number (in step 1)
>> so I have to add 102 to the 'bytes' and create new byte[] named NewBytes.
>>3. Get the character corresponding to the new byte:
>>
>> string Encrypted = Encoding.GetEncoding(1252).GetString(NewBytes);
>>
>>
>>The step two is what I am still not clear how to do.
>
>
>Step two seems ok - but I'd prefer to store a byte array
>
>
http://msdn.microsoft.com/en-us/goglobal/cc305145>
>There are some values that are not a char in codepage 1252
>Seems to work - but will it be without any problem in the future - I don;t know
>
>
>
>internal static void Go()
> {
> byte[] bytes = new byte[] {0x81, 0x8d, 0x8f, 0x90 };
> string s = Encoding.GetEncoding(1252).GetString(bytes);
>
> char[] c = s.ToCharArray();
>
> int l = s.Length;
> }
>
I did figure out how to use my Step 2 and the code works! I will check your link of storing byte array. And see if I can apply it to the case of string stored by VFP. In the future, when all my customers convert to SQL Server, I will change the encryption of password so something more "standard." But for now this will work.
Thank you very much!
"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