C# 如何使前4个字母成为下一个文本框中的大写字母?

C# 如何使前4个字母成为下一个文本框中的大写字母?,c#,uppercase,toupper,C#,Uppercase,Toupper,新的编程和它的用户/密码生成器。我希望在左文本框中每个名称的前4个字母,结果应该是4个大写字母(I)生成相同的4个大写字母/密码 例: 我的代码: public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void buttonGenerat_Click(object sender, E

新的编程和它的用户/密码生成器。我希望在左文本框中每个名称的前4个字母,结果应该是4个大写字母(I)生成相同的4个大写字母/密码

例:

我的代码:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonGenerat_Click(object sender, EventArgs e)
        {
            char[] radbytning = new char[]{'\r', '\n'};
            string[] name = textBoxLeft.Text.Split(radbytning, StringSplitOptions.RemoveEmptyEntries);
            string result = "";
            for (int i = 0; i <name.Length; i++)
            {
                result += string.Format("{0}{1}{0} / {2}\r\n", name[i].Substring(0, 4), i, GeneratPassword());
            }

            textBoxRight.Text = result;

        }

        private static string GeneratPassword() 
        {
            string result = "";
            String tecken = "abcdefghijklmnopqrstuvxyzåäö1234567890ABCDEFGHIJKLMNOPQRSTUVXYZÅÄÖ";
            Random random = new Random();
            for(int i = 0; i< 8; i++)
            {
                result += tecken[random.Next(tecken.Length)].ToString();
                System.Threading.Thread.Sleep(10);
            }
            return result;
        }

          public string FirstLetterToUpper(string)
        {
            if (str == null)
                return null;

            if (str.Length > 1)
                return char.ToUpper(str[0]) + str.Substring(1);

            return str;
        }
    }
}
公共部分类表单1:表单
{
公共表格1()
{
初始化组件();
}
私有无效按钮生成单击(对象发送者,事件参数e)
{
char[]radbytning=new char[]{'\r','\n'};
string[]name=textBoxLeft.Text.Split(radbytning、StringSplitOptions.RemoveEmptyEntries);
字符串结果=”;
对于(int i=0;i 1)
返回字符ToUpper(str[0])+str.Substring(1);
返回str;
}
}
}

这行代码引发错误,因为您要传递的“字符串”没有附加变量
公共字符串firstletttouper(字符串)

然而,我认为您根本不需要这个函数,甚至在代码中都不调用它

我认为您只需更改以下代码行即可获得所需内容并删除我上面提到的函数:

result += string.Format("{0}{1}{0} / {2}\r\n", name[i].Substring(0, 4), i, GeneratPassword());
改为:

result += string.Format("{0}{1}{0} / {2}\r\n", name[i].Substring(0, 4).ToUpper(), i, GeneratPassword());
然后给出一个输出

ADAI0ADAI / CMldQQY7
ZORR0ZORR/e3sbdxJQ


我想这就是你的意思,在你的问题的这一部分你有多处打字错误

请不要在一篇文章中问多个问题。
ADAI0ADAI / CMldQQY7