Yeah, thanks Rick ... that's about the same thing that Cathi said in her reply.
~~Bonnie
>That's because strings are Unicode and aren't represented through ASCII codes. Unicode is double byte, so when you get that value you're getting only the first of the two bytes.
>
>There are a number of complicated ways to do this. Basically you have to change the encoding of the string to ASCII and stream it into a Byte Array. Then you can read the individual character as standard 8 bit ASCII. I don't remember offhand how this works, but if you look at the HTTP Web Request article at:
http://www.west-wind.com/articles.asp there's a bunch of stuff in there on string encoding...
>
>+++ Rick ---
>
>
>>Cathi,
>>
>>The weird thing about this is that it doesn't appear that your mychar is actually the same thing.
>>
>>
>>Char mychar = (char)149;
>>MessageBox.Show(mychar.ToString());
>>
>>
>>This shows a different character than what I see if I do the same thing in VFP:
>>
>>
>>mychar = CHR(149)
>>MessageBox(mychar)
>>
>>
>>Any idea what's going on?
>>
>>~~Bonnie
>>
>>
>>>I just ran this sample code and it returned 149. Try this and see what you get:
>>>
>>>
>>>String cString;
>>>Char mychar;
>>>mychar=(char)149;
>>>cString = mychar.ToString() + "ABC";
>>>int lnChar = (int)Char.Parse(cString.Substring( 0, 1 ));
>>>
>>>
>>>
>>>>I'm having a problem with some ascii codes here and I can't figure it out. It would be great if someone could help me. Anyway, in VFP:
>>>>
>>>>?chr( asc(chr(149))
>>>>
>>>>displays some weird symbol, but a symbol I need.
>>>>
>>>>the problem is with the chr(149). Of course, I'm not actually using
>>>>'chr(149)', but the appropriate character. Just doing it this way for display purposes here.
>>>>Now, if I had a string that began with chr(149), in c#:
>>>>
>>>>int nAscVal = (int)Char.Parse( cString.Substring( 0, 1 ) )
>>>>
>>>>
>>>>nAscVal now has a value of 8226, it should be 149.
>>>>
>>>>It must have something to do with the encoding, but I don't know what. I've tried some stuff, like:
>>>>
>>>>int pintAsc = (new ASCIIEncoding()).GetBytes(new char[]{Char.Parse( cString.Substring( 0, 1 ))})[0];
>>>>
>>>>but no matter what character I select with the substring, it always returns a value of 63 to pintAsc. I'm lost on this one, anyone got any clues? Thanks,
>>>>jfh