Click here to Skip to main content
13,143,774 members (29,031 online)
Rate this:
Please Sign up or sign in to vote.
See more:
My problem is that I have been trying to make a letter increment as such:

a-b-c-d etc then when it gets to z go: aa-ab-ac-ad... ba-bb-bc-bd and so on.

And if any user simply input the latter a, it should be give output 1 and z-26, and so on

For Example-
User input a then output should be 1
User input z then output should be 26
User input aa then output should be 27

This series will go upto zz

If anyone knows a simple solution to this please respond. I will keep trying but not seccess.
Posted 16-Feb-13 19:35pm
Sandeep Mewara 17-Feb-13 2:03am
It does not work like this here.

Here is what is expected of enquirers:
1. TRY first what you want to do! You may find that it's not that hard.
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.
riteshsingh_jsr 17-Feb-13 2:06am
How can I increment the loop after z... I have displayed a-z only how can I display aa to zz
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

This smells like homework, so I will give you no code!
However, it really isn't a complex task:

1) Set up a loop - this can be a "while true" loop
2) Read the input from the user using Console.ReadLine
3) If the input is blank (I would use string.IsNullOrWhitespace for this) exit the loop.
4) Initialize a sum to zero.
5) For each character in the input string, go round another loop
5.1) If the character is between 'a' and z' inclusive,
5.1.1) Multiply the sum by 26.
5.1.2) Subtract 'a' from the character, and add one (this converts a to 1, b to 2 and so on)
5.1.3) Add the value from 5.1.2 to your sum.
5.1.4) Go round the character loop at (5)
6) Print the sum
7) Go back round the loop at (2)
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This will work for you

65 = "A".charCodeAt(0);
66 = "B".charCodeAt(0);
OriginalGriff 17-Feb-13 2:57am
Reason for my vote of one: Read the question. This does not answer it or even begin to answer it!
riteshsingh_jsr 18-Feb-13 6:15am
Sorry dear, i was not able to understand your solution.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Sorry dear it's my new code according to your question it's working fine according to me, if you feel any issue there you can contact to me

function GetValues() {
            var val = document.getElementById('<%=TextBox1.ClientID %>').value;
            var alphaArray = "abcdefghijklmnopqrstuvwxyz";
            var totalChars = alphaArray.length;
            var index = 0;
            var subtotal = 0;
            if (val.length == 1) {
                index = alphaArray.indexOf(val) + 1;
            else if (val.length == 2) {
                var firstChar = val.substring(0, 1);
                var secondChar = val.substring(1, 2);
                var charPosition = totalChars * (alphaArray.indexOf(firstChar) + 1);
                index = (alphaArray.indexOf(secondChar) + 1) + charPosition;

Please don't forgot to give me points.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170915.1 | Last Updated 17 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100