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 end value in the 6th column in order to remove it from a list. The length of the value in the 6th column is undetermined and can contain any character. So what I would like to do is match the end value before a space. or just the end of the line.
CODE:
// 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");
What I am trying to do is get the file to 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 anyone 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
}
foreach (var theLine in mainResult) {theLine.Split(' '); theResult.Add(string.Join(theLine[0] + theLine[1] + theLine[2] + theLine[3] + theLine[4]));}
? – Epigenesis' '
and discard the last field. – Disgrace