Re: Comparing char to ascii char

"Marsh, Drew" <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.general
Message-ID <[email protected]>
Christopher Slowik [mailto:[email protected]] wrote:

> I'm using c# and need to compare each character in a string
> to see if its an ascii dec 022.  How do you declare an ascii
> char in c#.  Does c# have a chr function.  I don't seem to be
> able to find anything.  TIA

The System.Char datatype in the CLR is unicode. You can define your ascii
character variable as a byte and assign initialize it like so:

<codeSnippet language="C#">
byte asciiA = (byte)'A';
</codeSnippet>

The value of asciiA will be 65. Also, you can also convert characters and
strings to ASCII at runtime using
System.Encoding.ASCII.GetBytes/GetString().

HTH,
Drew

[ .NET MVP | weblog: http://radio.weblogs.com/0104813/ ]

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.