Hi. I have a project and it requires me to search a number from a name and put it into my filepath. For example:
The name is LU610364G02
and the filepath should be: ..\Reports\2016\10\LU610364\
where 2016 is the 3rd number from LU610364G02, 10 is the 4th and 5th number and LU610364 is the first 8 numbers.
How do I search the values and put it into the filepath?
I am using Microsoft Visual Studio, c#.
Thank you in advance for the help
What I have tried:
Tried using Regex as an expression to match the name to the filepath.
<pre lang="c#"> string Timestamp = string.Empty;
using (var file = System.IO.File.OpenText(datFile))
{
Regex nodeRegex = new Regex("NODE :(.*)", RegexOptions.IgnoreCase);
Regex testModeRegex = new Regex("\bTest Mode\b", RegexOptions.IgnoreCase);
Regex program = new Regex("\bPROGRAM\b", RegexOptions.IgnoreCase);
Regex TimeStamp = new Regex("\bTIMESTAMP\b", RegexOptions.IgnoreCase);
while (!file.EndOfStream)
{
String line = file.ReadLine();
Match m = nodeRegex.Match(line);
string match = string.Format(@"\b{0}\b", FAR_Yield_Analysis_Test_Tool.Properties.Settings.Default.RegexTestMode);
bool matchTestMode = Regex.IsMatch(line, match, RegexOptions.IgnoreCase | RegexOptions.Singleline);
Match matchTest = Regex.Match(line, FAR_Yield_Analysis_Test_Tool.Properties.Settings.Default.RegexTestMode);
Match matchProgram = Regex.Match(line, FAR_Yield_Analysis_Test_Tool.Properties.Settings.Default.RegexPROGRAM);
Match matchTimestamp = Regex.Match(line, FAR_Yield_Analysis_Test_Tool.Properties.Settings.Default.RegexTimestamp);
if (matchTest.Success)
{
int startIndex = matchTest.Index + FAR_Yield_Analysis_Test_Tool.Properties.Settings.Default.RegexTestMode.Length + 1;
int endIndex = line.IndexOf(' ', startIndex + 1);
TestMode = line.Substring(startIndex, endIndex - startIndex).Trim();
}
if (matchProgram.Success)
{
int startIndex = matchProgram.Index + FAR_Yield_Analysis_Test_Tool.Properties.Settings.Default.RegexTestMode.Length + 1;
int endIndex = line.IndexOf(' ', startIndex + 1);
strProgram = line.Substring(startIndex, endIndex - startIndex).Trim();
}
if (matchTimestamp.Success)
{
int startIndex = matchTimestamp.Index + FAR_Yield_Analysis_Test_Tool.Properties.Settings.Default.RegexTimestamp.Length + 1;
int endIndex = line.IndexOf(' ', startIndex + 1);
strTimestamp = line.Substring(startIndex, endIndex - startIndex).Trim();