By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,647 Members | 1,598 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,647 IT Pros & Developers. It's quick & easy.

how to generate a list a alphabet using csharp?

P: n/a
one
greetings

i am just wondering if some expert here can either show me how to do this or point me to the right direction (url...

i want to use c# to generate a list of alphabet e.g
A B C ... AA AB AC AD ... AAB ... ZZZZY ... ZZZZ

any suggestion will be greatly appreciated

thank you
on

Nov 16 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Google: "c#"+"recursion"

--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

"one" <on***********@online.nospam> wrote in message
news:AF**********************************@microsof t.com...
greetings,

i am just wondering if some expert here can either show me how to do this or point me to the right direction (url...)
i want to use c# to generate a list of alphabet e.g.
A B C ... AA AB AC AD ... AAB ... ZZZZY ... ZZZZZ

any suggestion will be greatly appreciated.

thank you
one

Nov 16 '05 #2

P: n/a
one
no, too many crap result. most of them show how to use for loop, while loop etc

any other (more) precise search

----- clintonG wrote: ----

Google: "c#"+"recursion

--
<%= Clinton Gallaghe
A/E/C Consulting, Web Design, e-Commerce Software Developmen
Wauwatosa, Milwaukee County, Wisconsin US
NET csgallagher@ REMOVETHISTEXT metromilwaukee.co
URL http://www.metromilwaukee.com/clintongallagher

"one" <on***********@online.nospam> wrote in messag
news:AF**********************************@microsof t.com..
greetings
i am just wondering if some expert here can either show me how to do this o point me to the right direction (url... i want to use c# to generate a list of alphabet e.g

A B C ... AA AB AC AD ... AAB ... ZZZZY ... ZZZZ
any suggestion will be greatly appreciated
thank yo

on

Nov 16 '05 #3

P: n/a
> >> i want to use c# to generate a list of alphabet e.g.
> A B C ... AA AB AC AD ... AAB ... ZZZZY ... ZZZZZ
>> any suggestion will be greatly appreciated.


I don't see why this has to involve recursion.

First decide exactly what you're doing. I think the following is the
pattern you have in mind:

(1) If the string does not end in Z, then change its last letter to the next
letter in the alphabet.

Thus A is followed by B, AA is followed by AB, BLITHERA is
followed by BLITHERB, etc.

(2) If the string *does* end in Z, then, starting from the end, work back
until you find a letter that is not Z, and change it to the next letter in
the alphabet; then replace all the letters after it with A.

Thus AZZ is followed by BAA.

(3) But if you get all the way to the beginning and have all Z's, then
change it to all A's with one more letter.

Thus ZZZ is followed by AAAA.
At least I *think* that's what you have in mind. Is it? If so, it should
be easy to do with StringBuilder (which is mutable, unlike String) and some
simple program logic.
Steps (2) and (3) can be consolidated because, starting from the end, you're
replacing Z's with A's.
P.S. Be sure to acknowledge me when you turn in your homework... if this is
homework.

--
----------------------------------------------------------------------------
---------
Michael A. Covington, Associate Director
Artificial Intelligence Center, The University of Georgia
http://www.ai.uga.edu/~mc

Nov 16 '05 #4

P: n/a
Hi one,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to generate a list of alphabet
using C#.If there is any misunderstanding, please feel free to let me know.

Here I have written a code snippet for you. HTH.

private void Form1_Load(object sender, System.EventArgs e)
{
StreamWriter sw = new StreamWriter(@"c:\recursion.txt");
for(int i=1;i<4;i++)
{
this.AToZ("", 1, sw, i);
}
sw.Close();
}

private void AToZ(string prefix, int level, StreamWriter sw, int length)
{
if(level<=length)
{
for(int i=0;i<26;i++)
{
string p = prefix + Convert.ToChar((Convert.ToInt32('A') + i));
this.AToZ(p, level+1, sw, length);
}
}
else
{
sw.WriteLine(prefix);
}
}

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #5

P: n/a
Hi Kevin

Yes, this is exactly what I want to do. And you code works perfectly fine. One question though, how would I create the list without using a "helper" function? I.e. in a console application. Just let me know the pseudo steps, if you can

By the way, you code is very neat. Where did you learn that

Thanks again
one
Nov 16 '05 #6

P: n/a
one
Hey thanks for the steps Michael

Yep, you are spot on. that's exactly what I meant. However, I ran into some problem with my logic. It produces a list that looks like this
A...Z...AZ...AAA...AAZ...AAA

Istill can't get my head round this one

I will try further. But thanks for your time

on

Nov 16 '05 #7

P: n/a
Hi one,

I'm afraid a helper function cannot be avoided if we are using recursive
loop, because a recursive loop has to call itself and we need another
function to call it. In a console application, you can also put the
following code in main().

static void Main(string[] args)
{
StreamWriter sw = new StreamWriter(@"c:\recursion.txt");
for(int i=1;i<4;i++)
{
this.AToZ("", 1, sw, i);
}
sw.Close();
}

It is a typical algorithmic problem. I learned these when I was preparing
to attend the International Collegiate Programming Contest, which was held
by Association of Computer Machinery as a college student. ;-)

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #8

P: n/a
"onett fd" write:
By the way, you code is very neat. Where did you learn that?


If one wants to engage into programming just slightly serious, one should be
familiar with recursion.
Look at something like
http://personal.vsnl.com/erwin/recursion.htm
http://www-2.cs.cmu.edu/~cburch/surv...rse/index.html
http://www.cs.princeton.edu/~lworthi...recursion.html

or google for "recursion"...

It will help you to be able to solve lots of problems in an easy way and
understand about breaking them into smaller pieces to solve each of these...
Nov 16 '05 #9

P: n/a
one
Great links. Thanks Michael. I wish I know them ealier. :-)

"Michael Voss" wrote:
"onett fd" write:
By the way, you code is very neat. Where did you learn that?


If one wants to engage into programming just slightly serious, one should be
familiar with recursion.
Look at something like
http://personal.vsnl.com/erwin/recursion.htm
http://www-2.cs.cmu.edu/~cburch/surv...rse/index.html
http://www.cs.princeton.edu/~lworthi...recursion.html

or google for "recursion"...

It will help you to be able to solve lots of problems in an easy way and
understand about breaking them into smaller pieces to solve each of these...

Nov 16 '05 #10

P: n/a
one
That's great. Thank you very much

O, can you tell me if there is any thing like a Base26 value which I can use to create the alphabet list? Like a web counter or a car speedometer. But instead of changing form 0 to 1, it will be Z to A

Is it possible at all

one
Nov 16 '05 #11

P: n/a
Hi One,

It seems that if you need such a class, you have to implement it yourself.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #12

P: n/a
one
Cool, thanks for you quick response!

"Kevin Yu [MSFT]" wrote:
Hi One,

It seems that if you need such a class, you have to implement it yourself.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.