返回null的char值

时间:2016-10-26 19:28:55

标签: c# char maxlength letters-and-numbers

这是我的代码;

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值但似乎是空的。

AllCharacters

如果选中,则填充TextBox,但for循环不起作用。原因可能是0 TextBox的字符数,但TextBox已填充。

MaxLength

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

1 个答案:

答案 0 :(得分:1)

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

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

    for (int i = 0; i < TextBox.Text.Length; i++)
    {
         char Characters = LowerText[i];
         ...
    }