У меня есть файл, который выглядит так:
J6 INT-00113G 227.905 5.994 180 ~!@#$%&^)
J3 INT-00113G 227.905 -203.244 180 12341341312315
U13 EXCLUDES -42.210 181.294 180 QFP128
U3 IC-00276G 5.135 198.644 90 B%GA!@-48
U12 IC-00270G -123.610 -201.594 0 SOP8_000
J1 INT-00112G 269.665 179.894 180 SOIC16_1
J2 INT-00112G 269.665 198.144 180 SOIC16-_2
.. .......... ....... ....... ... ................
И я бы хотел сопоставить конечное значение в 6-й столбец , чтобы удалить его из списка. Длина значения в 6-м столбце не определена и может содержать любой символ. Поэтому я хотел бы сопоставить конечное значение перед пробелом . или просто конец строки.
КОД:
// Reads the lines in the file to format.
var fileReader = File.OpenText(filePath + "\\Remove Package 1 Endings.txt");
// Creates a list for the lines to be stored in.
var fileList = new List<string>();
// Adds each line in the file to the list.
while (true)
{
var line = fileReader.ReadLine();
if (line == null)
break;
fileList.Add(line);
}
var mainResult = new List<string>();
var theResult = new List<string>();
foreach (var mainLine in fileList)
mainResult.Add(string.Join(" ", mainLine));
foreach (var theLine in mainResult)
{
// PLACEMENT ONE Regex
Match theRegex = Regex.Match(theLine, @"insert the regex here!");
if (theRegex.Success)
theResult.Add(string.Join(" ", theLine));
}
// Removes the matched values from both of the Regex used above.
List<string> userResult = mainResult.Except(theResult).ToList();
// Prints the proper values into the assigned RichTextBoxes.
foreach (var line in userResult)
richTextBox2.AppendText(line + "\n");
Я пытаюсь сделать так, чтобы файл выглядел так:
J6 INT-00113G 227.905 5.994 180
J3 INT-00113G 227.905 -203.244 180
U13 EXCLUDES -42.210 181.294 180
U3 IC-00276G 5.135 198.644 90
U12 IC-00270G -123.610 -201.594 0
J1 INT-00112G 269.665 179.894 180
J2 INT-00112G 269.665 198.144 180
ВОПРОС:
- Кто-нибудь может помочь придумать для этого регулярное выражение?
EDIT:
ДОБАВЛЕННЫЙ КОД:
var lines = new List<string>(File.ReadAllLines(filePath + "\\Remove Package 1 Endings.txt"));
for (int i = 0; i < lines.Count; i++)
{
var idx = lines[i].LastIndexOf(" ");
if (idx != -1)
lines[i] = lines[i].Remove(idx);
richTextBox1.AppendText(lines[i] + Environment.NewLine
}