txtinput 中的原始文本将以这种格式显示
Firstportion Seconportion
Firstportion Seconportion
Firstportion Seconportion
Firstportion Seconportion
我的目标是首先将每行拆分为两个变量,然后将它们添加到数组或列表或任何有效的方法中[行数是可变的,因此数组不起作用]
var1[] = firstportion, var2=seconportion //到目前为止看起来像是为第一个条目工作
把它们放到变量数组/列表中[不适用于我目前拥有的循环]
使用条件 if 和正则表达式分别处理第一部分和第二部分,并将它们全部显示在第二个 txtbox
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; using System.Collections; using System.Text.RegularExpressions; namespace Projectx { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string rawInput = txtInput.Text; //string[] rawInput = txtInput.Text.Split('\n'); int x = 1; int y = 1; foreach (string line in txtInput.Lines) { string firstPortion= ""; string secondPortion = ""; string[] splitInput = Regex.Split(rawInput, ("\\s+")); firstPortion= splitInput[0]; secondPortion = splitInput[1]; //##### This works so far ans splits each line into two variables seperated by 1 white space but not sure if it works for 2nd line and seems can't assign these new splited values into two seperate array or list with the same loop or seperate loop //List<int> list = new List<int>; //(arr) List<string> myList1 = new List<string>(); List<string> myList2 = new List<string>(); myList1.Add(firtPortion); myList2.Add(secondPortion); txtOutPut.Text = "modified " + myList1[x] + " " + myList2[y]+"\r\n"; int i = 1; i++; x++; y++; } } } }