The simple way to do this is to cast to byte, increment, then cast back to
char. Like so:
--
char ch = 'a';
byte bt = (char)ch;
bt++;
ch = (char)bt;
--
Problem is, char's can be unicode as well... it would probably be better to
use System.Encoding.ASCII. Like so:
--
char ch = 'a';
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(new char[] {ch});
bytes[0]++;
ch = System.Text.Encoding.ASCII.GetChars(bytes)[0];
--
I don't particularly like either of these methods, as they rely on the ASCII
codes being sequential. Personally, I would rather generate a lookup table
array and index into that instead...
Chris
-----Original Message-----
From: Doug Wilson [mailto:[EMAIL PROTECTED]
Sent: Wednesday, July 07, 2004 5:40 PM
To: [EMAIL PROTECTED]
Subject: [AspNetAnyQuestionIsOk] Get Next Character
Hi All
I need to increment a character counter. For example, if I was passed the
character 'a' as a parameter I would need to return 'b'. If passed 'c', then
return 'd'.
So, the way I assume to do it would be to convert to ASCII code, add 1 to
the ASCII code, and then convert back to it's character mapping, but have no
idea how to do this in C#.
If anyone has done this or knows how, please let me know urgently.
Thanks and regards
------------------------ Yahoo! Groups Sponsor --------------------~-->
Yahoo! Domains - Claim yours for only $14.70
http://us.click.yahoo.com/Z1wmxD/DREIAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
------------------------ Yahoo! Groups Sponsor --------------------~-->
Yahoo! Domains - Claim yours for only $14.70
http://us.click.yahoo.com/Z1wmxD/DREIAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/