Click here to Skip to main content
15,885,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Comments
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

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)
 
Share this answer
 
This will work for you

65 = "A".charCodeAt(0);
66 = "B".charCodeAt(0);
 
Share this answer
 
Comments
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.
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 syedasim8@hotmail.com

JavaScript
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;
                
            }
document.write(index);
        }



Please don't forgot to give me points.
Thanks
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900