-2

这是我的代码;

public void Dönüştür()
{
    int TextboxLength = TextBox.MaxLength;
    string LowerText = TextBox.Text.ToLower();
    var AllCharacters = "";

    for (int i = 0; i < TextboxLength; i++)
    {
        char Characters = char.Parse(LowerText);
        switch (Characters)
        {
            case '0': AllCharacters += "0"; break;
            case '1': AllCharacters += "1"; break;
            case '2': AllCharacters += "2"; break;
            case '3': AllCharacters += "3"; break;
            case '4': AllCharacters += "4"; break;
            case '5': AllCharacters += "5"; break;
            case '6': AllCharacters += "6"; break;
            case '7': AllCharacters += "7"; break;
            case '8': AllCharacters += "8"; break;
            case '9': AllCharacters += "9"; break;

            case ' ': case '+': case '-': case '_': AllCharacters += "0"; break;
            case ':': case ';': case '=': case ',': case '.': AllCharacters += "1"; break;
            case 'a': case 'b': case 'c': case 'ç': AllCharacters += "2"; break;
            case 'd': case 'e': case 'f': AllCharacters += "3"; break;
            case 'g': case 'ğ': case 'h': case 'ı': case 'i': AllCharacters += "4"; break;
            case 'j': case 'k': case 'l': AllCharacters += "5"; break;
            case 'm': case 'n': case 'o': case 'ö': AllCharacters += "6"; break;
            case 'p': case 'r': case 's': case 'ş': AllCharacters += "7"; break;
            case 't': case 'u': case 'ü': AllCharacters += "8"; break;
            case 'v': case 'y': case 'z': case 'x': case 'w': AllCharacters += "9"; break;
        }

    }
    MessageBox.Show(TextBox.MaxLength.ToString(), "TextBox MaxLength:");
    MessageBox.Show(AllCharacters.ToString(), "AllCharacters value:");
}

我想将数字转换为字母。char 值,但它似乎为空。

所有字符

如果选中,则填充 TextBox,尽管 for 循环不起作用。造成这种情况的原因可能是 0 TextBox 的字符数但 TextBox 已填充。

最长长度

问题是什么,我在哪里犯错?

4

1 回答 1

1

您正在循环 指定的次数TextBox.MaxLength,该次数为零,因此它根本不循环。你的意思是循环TextBox.Text.Length吗?

如果该MaxLength属性设置为大于零,则限制可以输入到文本框中的字符数。

    for (int i = 0; i < TextBox.Text.Length; i++)
    {
         char Characters = LowerText[i];
         ...
    }
于 2016-10-26T19:33:26.453 回答