将2个文本框内容与定界符组合 [英] Combine 2 textbox contents with delimiter
问题描述
我有一个问题。可以说我有2个文本框,其中一个带有以下内容:
I'm having a bit of an issue. Lets say I have 2 text boxes, one on the left with this content:
Win
Lose
Hello
Goodbye
在右侧,显示以下信息:
And one on the right, with this information:
One
Two
Three
Four
现在,在按下按钮时,我想将这两个文本框与冒号分隔在一起,因此它将输出如下:
Now, on button press, I want to combine these two text boxes with colon delimitation, so it would output like this:
Win:One
Lose:Two
Hello:Three
Goodbye:Four
有什么想法可以做到吗?到目前为止,我没有尝试过任何方法。这是我当前的代码,抱歉。我不是想让你为我做我的工作,我只是很困惑:
Any idea how I can accomplish this? Nothing I have tried thus far has worked. This is my current code, sorry. I'm not trying to have you do my work for me, I'm just rather confused:
string path = Directory.GetCurrentDirectory() + @"\Randomized_List.txt";
string s = "";
StringBuilder sb = new StringBuilder();
StreamReader sr1 = new StreamReader("Randomized_UserList.txt");
string line = sr1.ReadLine();
while ((s = line) != null)
{
var lineOutput = line+":";
Console.WriteLine(lineOutput);
sb.Append(lineOutput);
}
sr1.Close();
Console.WriteLine();
StreamWriter sw1 = File.AppendText(path);
sw1.Write(sb);
sw1.Close();
推荐答案
下面的代码演示了一种分割字符串然后连接它们。起初我误解了这个问题。 :)
The code below demonstrates one way of splitting strings and then concatenating them. I misunderstood the question at first. :)
string left = string.Format("Win{0}Lose{0}Hello{0}Goodbye", Environment.NewLine);
string right = string.Format("One{0}Two{0}Three{0}Four", 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;
}
}
这篇关于将2个文本框内容与定界符组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!