473,840 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to generate a list a alphabet using csharp?

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
12 14657
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******** *************** ***********@mic rosoft.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
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#"+"recur sion

--
<%= 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******** *************** ***********@mic rosoft.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
> >> 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
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 misunderstandin g, please feel free to let me know.

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

private void Form1_Load(obje ct sender, System.EventArg s e)
{
StreamWriter sw = new StreamWriter(@" c:\recursion.tx t");
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<=lengt h)
{
for(int i=0;i<26;i++)
{
string p = prefix + Convert.ToChar( (Convert.ToInt3 2('A') + i));
this.AToZ(p, level+1, sw, length);
}
}
else
{
sw.WriteLine(pr efix);
}
}

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
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
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...AA A...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
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.tx t");
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
"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
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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3512
by: tjland | last post by:
Okay so im working on a very simple encryption method using just loops. Kind of novel i think. Okay so first i set up a list of the alphabet with just every seperate letter, then user is prompted for a word, this is not user friendly just for me. Ok now as you can see below this is pretty basic, if u can follow all the loops i get to a point where I have the letter positions in the list for the final word but i dont know of a way to come...
21
3843
by: M. Clift | last post by:
Hi All, Could someone help me out with this? items = ('a', 'b', 'c', 'd') items + 1 = ( 'b', 'c', 'd', 'a') items + 2 = ( 'c', 'd', 'a', 'b') items + 3 = ( 'd', 'a', 'b', 'c') trans = 1
2
1821
by: one | last post by:
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
2
2967
by: Peter R | last post by:
Hi, Probably this question was asked before, but what is the algorithm to generate all combinations based on N numbers? For example, for 3 elements = {1,2,3}, I'd like to generate a list of (2^n - NULL): 1, 2, 3 1, 2 2, 3
3
2062
by: pmud | last post by:
Hi, I have 2 drop down lists on an asp.Net page. The 1st contains alphabets. When the user selects an alphabet frm the first list, the second drop down list should be populated with names from the sql database, which begin with that alphabet. For this I used an sql data Adapter & created a data set. The user's selection in 1st list is passed as parameter to the sql statement.
28
3069
by: Rob Cowie | last post by:
Hi all, I wish to generate a sequence of the form 'aaa', 'aab', aac'.... 'aba', 'abb', 'abc' etc. all the way to 'zzz'. How would you construct a generator to acheive this? A simple, working but somewhat inelegant solution is... alpha = #shortened for brevity
8
3580
by: dohyohdohyoh | last post by:
I have a programming question to generate an ordered list of alphanumeric strings of length 4. two alphabets rest numberst, etc. EG 0000-9999 then A000-Z999 then AA00 to ZZ99 then AAA0 - ZZZ9 then AAAA - ZZZZ
3
5858
by: dohyohdohyoh | last post by:
I have a programming question to generate an ordered list of alphanumeric strings of length 4. two alphabets rest numberst, etc. EG 0000-9999 then A000-Z999 then AA00 to ZZ99 then AAA0 - ZZZ9 then AAAA - ZZZZ
4
11287
by: ssecorp | last post by:
In Haskell I can do for range(1,11) and for a list of the alphabet. Is there a way in Python to generate chars?
0
9860
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9699
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9440
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7838
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7023
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4076
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3138
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.