Saturday, March 24, 2012

loop throw alphabet

for (i =Convert.ToInt32('A'); i <=Convert.ToInt32('Z');i++)

i want to use that letters..how can i make that?

if i use convert.ToString method it returns ASCII

Try with this:

for (int i = 65; i <= 90; i++)
{
Response.Write("&#" + i + "<br/>");
}


Or you can use your code like this:

for (int i = Convert.ToInt32('A'); i <= Convert.ToInt32('Z'); i++)
{
Response.Write("&#" + i + "<br/>");
}


Instead of Convert.ToString use Convert.ToChar

for (int i = Convert.ToInt32('A'); i <= Convert.ToInt32('Z'); i++)
{
char c=Convert.ToChar(i);
}


Wouldnt it be easier on the processing to do something like this?

private const _ALPH = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

foreach(char c in _ALPH)

{
// do something
}

?


no conversions needed, here it is for lower case alphabet

char letter ='a';while (letter !='z' + 1) { txtOutput.Text += letter; letter++; }
for uppercase juse make a -> A and z->Z

Sometimes there are very simple solutions to complex questions ;)

for (char alpha ='a'; alpha <='z'; alpha++)

{

Response.Write(alpha);

}


yeah..thanks i figured it out later..

0 comments:

Post a Comment