Karl66
asked on
C# using "num = input.Substring(indexOne + 6, 53);" to get the rest of the string?
I am the following code to find a keyword in a text file. When I find it I want to capture the rest of the line. But some lines are 53 and some are 56 and maybe longer. If I put in 56 it errors out on lines that are only 53. Any thoughts?
Karl66
if (File.Exists(path + @"\tmp\ssm.txt"))
{
int indexOne = -1; // ondex of ser #
int indexTwo = -1; // index of a space after a number
string num = "";
// Read file to list
StreamReader sr = File.OpenText(path + @"\tmp\ssm.txt");
string input = null;
while ((input = sr.ReadLine()) != null)
{
indexOne = input.IndexOf("Host UDO");
if (indexOne > -1)
{
num = input.Substring(indexOne + 6, 53);
break; // exit loop
}
}
lblLibrary.Text = num; // not really a num
return path;
// sr.Close();
}
Karl66
if (File.Exists(path + @"\tmp\ssm.txt"))
{
int indexOne = -1; // ondex of ser #
int indexTwo = -1; // index of a space after a number
string num = "";
// Read file to list
StreamReader sr = File.OpenText(path + @"\tmp\ssm.txt");
string input = null;
while ((input = sr.ReadLine()) != null)
{
indexOne = input.IndexOf("Host UDO");
if (indexOne > -1)
{
num = input.Substring(indexOne + 6, 53);
break; // exit loop
}
}
lblLibrary.Text = num; // not really a num
return path;
// sr.Close();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
num = input.Substring(indexOne + 6, input.Length);
you are right of course :)
Ed.