I have a file that looks like this:
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
.. .......... ....... ....... ... ................
And I would like to match the final value in the 6th column to remove it from the list. The length of the value in the 6th column is not defined and can contain any character. So what I would like to do is match the final value before the space. or just the end of the line.
CODE:
var fileReader = File.OpenText(filePath + "\\Remove Package 1 Endings.txt");
var fileList = new List<string>();
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)
{
Match theRegex = Regex.Match(theLine, @"insert the regex here!");
if (theRegex.Success)
theResult.Add(string.Join(" ", theLine));
}
List<string> userResult = mainResult.Except(theResult).ToList();
foreach (var line in userResult)
richTextBox2.AppendText(line + "\n");
What I'm trying to do is make the file look like this:
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
Question:
- Can someone help come up with a regex for this?
EDIT:
ADDED CODE:
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
}
source
share