i want to use use Alphabetical characters in loop.. i mean the loop of alphabetical chars.
right now i am using this..
for(char a ='A'; a<'Z' ;a++)
{
///do something
}
it works fine.. but it only works for single character.. i want to more than 1 character some thing like this..
for(char a ='AA'; a<'ZG' ;a++)
{
///do something
} is there a way that i can do this.. please let me know.. Thanks for reading the post. look forward for your replies. Thanks Sheikh
what are you trying to achieve with this code? some more understanding might help with a solution, are you trying to sort through a list?
with your 2nd example char a ='AA' wont work because a char is a single letter. if you had a word and wanted to work with char you would probably have to move towards the foreach loop and evaluate each char in your string.
String Start="AG";
String End="DZ";
for(int i=0; i<Start.Length; i++)
{
int startindex=(int)Start[i];
int endindex= (int)End[i];
for(int j=0; j<endindex ;j++)
{
Console.WriteLine(((char)i).ToString());
}
Console.WriteLine("2nd");
}
Just a Quick Dirty but Accurate Solution 4 U...
Beware of bugs in the above code; I have only proved it correct, not tried it.
-------------------------------------------------------
Contact-Info:Adils.kiet@gmail.com
Sheikhans
Member
47 Points
85 Posts
how to use Alpahabetical loop in C#
Jan 07, 2013 11:01 PM|LINK
Hi.
i want to use use Alphabetical characters in loop.. i mean the loop of alphabetical chars.
right now i am using this..
for(char a ='A'; a<'Z' ;a++) { ///do something } it works fine.. but it only works for single character.. i want to more than 1 character some thing like this..for(char a ='AA'; a<'ZG' ;a++) { ///do something }is there a way that i can do this..
please let me know..
Thanks for reading the post.
look forward for your replies.
Thanks
Sheikh
chjones2008
Member
258 Points
168 Posts
Re: how to use Alpahabetical loop in C#
Jan 07, 2013 11:16 PM|LINK
oned_gk
All-Star
31661 Points
6473 Posts
Re: how to use Alpahabetical loop in C#
Jan 08, 2013 12:08 AM|LINK
try
for(char a ='A'; a<'Z' ;a++) { for(char b ='A'; b<'G' ;b++) { ///do something } }Myke
Member
60 Points
14 Posts
Re: how to use Alpahabetical loop in C#
Jan 08, 2013 01:52 AM|LINK
what are you trying to achieve with this code? some more understanding might help with a solution, are you trying to sort through a list?
with your 2nd example char a ='AA' wont work because a char is a single letter. if you had a word and wanted to work with char you would probably have to move towards the foreach loop and evaluate each char in your string.
Jugg3rNaut
Member
474 Points
109 Posts
Re: how to use Alpahabetical loop in C#
Jan 08, 2013 04:37 AM|LINK
String Start="AG"; String End="DZ"; for(int i=0; i<Start.Length; i++) { int startindex=(int)Start[i]; int endindex= (int)End[i]; for(int j=0; j<endindex ;j++) { Console.WriteLine(((char)i).ToString()); } Console.WriteLine("2nd"); } Just a Quick Dirty but Accurate Solution 4 U...-------------------------------------------------------
Contact-Info:Adils.kiet@gmail.com