首页 > 解决方案 > 尝试在 C# 中使用数组和 forloop 在 GUI 中创建亵渎过滤器,但 forloop 搞乱了 remove 方法

问题描述

这是我的阵列,

public String[] Swears = new string[22] {"bad words"}

这里面有22个脏话,这里就不放了。这工作得很好,但似乎在 forloop 中不起作用

这是用户输入其姓名的文本框,其中包含一个似乎不起作用的删除语句。当此代码运行时,它只能删除前 4 个脏话,但之后的脏话会导致错误

public void player1Name_TextChanged(object sender, EventArgs e)
    {
        for(int i =0; i<22; i++)
        {
           
            if (player1Name.Text == Swears[i])
            {
                int o = player1Name.Text.Length;
                player1Name.Text = (Swears[i].Remove(4));
                MessageBox.Show("please enter a valid Name");
            }
        }
       
    }

标签: c#profanity

解决方案


推荐阅读