将 2 个文本框文本与分隔符组合
Combine 2 textbox text with delimiter
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Text File|*.txt";
sfd.Title = "Save Text File";
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string path = sfd.FileName;
string left = string.Format(EmailTxtbx.Text, Environment.NewLine);
string right = string.Format(PasslTxtbx.Text, Environment.NewLine);
string[] leftSplit = left.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
string[] rightSplit = right.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
string output = "";
if (leftSplit.Length == rightSplit.Length)
{
for (int i = 0; i < leftSplit.Length; i++)
{
output += leftSplit[i] + ":" + rightSplit[i] + Environment.NewLine;
}
}
using (StreamWriter bw = new StreamWriter(File.Create(path)))
{
textBox1.Text = output;
bw.Write(output);
bw.Close();
}
}
嘿嘿。我有一个问题。假设我有 2 个我想要的文本框
在一起:
TextBox1:
测试 41
测试 414
测试 41
TextBox2:
测试55
测试 56
测试 54
TextBox3:
测试41:测试55
Test414:Test56
Test41:Test54
我想将 2 个文件加载到第一个文本框和第二个文本框,并与分隔符(如“:”)结合使用我试过这段代码,但它不起作用。我是 c# 新手。
希望有人能帮助我
I’ll start from scratch. I have 2 textbox. In the first textbok it’s the mails. In the second textbox it’s passwords. What I need to do to combine the textboxes with “:”
试试这个代码片段:
var txt1 = textBox1.Lines.Where(a => !string.IsNullOrEmpty(a)).ToArray();
var txt2 = textBox2.Lines.Where(b => !string.IsNullOrEmpty(b)).ToArray();
var txt3 = "";
for(int i = 0; i < txt1.Length; i++)
{
if (i < txt2.Length)
txt3 += $"{txt1[i]}:{txt2[2]}{Environment.NewLine}";
else
txt3 += $"{txt1[i]}{Environment.NewLine}";
}
textBox3.Text = txt3;
祝你好运。
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Text File|*.txt";
sfd.Title = "Save Text File";
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string path = sfd.FileName;
string left = string.Format(EmailTxtbx.Text, Environment.NewLine);
string right = string.Format(PasslTxtbx.Text, Environment.NewLine);
string[] leftSplit = left.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
string[] rightSplit = right.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
string output = "";
if (leftSplit.Length == rightSplit.Length)
{
for (int i = 0; i < leftSplit.Length; i++)
{
output += leftSplit[i] + ":" + rightSplit[i] + Environment.NewLine;
}
}
using (StreamWriter bw = new StreamWriter(File.Create(path)))
{
textBox1.Text = output;
bw.Write(output);
bw.Close();
}
}
嘿嘿。我有一个问题。假设我有 2 个我想要的文本框 在一起:
TextBox1:
测试 41
测试 414
测试 41
TextBox2:
测试55
测试 56
测试 54
TextBox3:
测试41:测试55
Test414:Test56
Test41:Test54
我想将 2 个文件加载到第一个文本框和第二个文本框,并与分隔符(如“:”)结合使用我试过这段代码,但它不起作用。我是 c# 新手。
希望有人能帮助我
I’ll start from scratch. I have 2 textbox. In the first textbok it’s the mails. In the second textbox it’s passwords. What I need to do to combine the textboxes with “:”
试试这个代码片段:
var txt1 = textBox1.Lines.Where(a => !string.IsNullOrEmpty(a)).ToArray();
var txt2 = textBox2.Lines.Where(b => !string.IsNullOrEmpty(b)).ToArray();
var txt3 = "";
for(int i = 0; i < txt1.Length; i++)
{
if (i < txt2.Length)
txt3 += $"{txt1[i]}:{txt2[2]}{Environment.NewLine}";
else
txt3 += $"{txt1[i]}{Environment.NewLine}";
}
textBox3.Text = txt3;
祝你好运。