【发布时间】:2016-03-19 15:00:24
【问题描述】:
编程新手及其用户/密码生成器。我想在左侧文本框中的每个名称中包含前 4 个字母,结果应该是 4 个大写字母(i)生成相同的 4 个大写字母/密码
例如:
Adair Ewing
Zorro Irving
(Pusching generatbutton)
(Result)
ADAI0ASAI / dkfnwkef
ZOOR1ZOOR / woeknfwe
我的代码:
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;
}
}
}
【问题讨论】:
-
请不要在帖子中提出多个问题。 One post with multiple questions or multiple posts?