显示字母数字 [英] Display number against alphabet

查看:70
本文介绍了显示字母数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我一直试图让字母增量如下:



abcd等然后当它到达z go:aa-ab-ac -ad ... ba-bb-bc-bd等等。



如果任何用户只输入后者a,则应该给出输出1和z -26,依此类推



例如 -

用户输入a输出应为1

用户输入z然后输出应该是26

用户输入aa然后输出应该是27



这个系列将达到zz

<





如果有人知道一个简单的解决方案,请回复。我会继续尝试但不会成功。

解决方案

这闻起来像家庭作业,所以我不会给你任何代码!

然而,它真的不是一项复杂的任务:



1)设置循环 - 这可以是while true循环

2)阅读来自用户的输入使用Console.ReadLine

3)如果输入为空(我将使用string.IsNullOrWhitespace)退出循环。

4)初始化a总和为零。

5)对于输入字符串中的每个字符,转到另一个循环

5.1)如果字符在''a''和z''之间包含,

5.1.1)将总和乘以26.

5.1.2)从字符中减去a,并加一个(这将转换为1,b到2,依此类推)

5.1.3)将5.1.2的值加到你的总和上。

5.1.4)绕过字符循环(5)

6)打印金额

7)围绕循环返回(2)


这对你有用



65 =A.charCodeAt(0);

66 =B.charCodeAt( 0);


对不起,亲爱的,根据你的问题我的新代码根据我的说法工作得很好,如果你觉得有什么问题可以联系我syedasim8 @ hotmail.com



  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);
}







请不要忘记给我积分。

谢谢


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.

解决方案

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)


This will work for you

65 = "A".charCodeAt(0);
66 = "B".charCodeAt(0);


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

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


这篇关于显示字母数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆