Jeff
Lord
Let me start with your flashback question... This link is probably one of the best out there for string formatting questions and lookup..(http://blog.stevex.net/string-formatting-in-csharp/). The very first example is regarding ,# formatting.
Now, back to the "Question 4" topic....the best way I can explain how to do what you were attempting to do is with a highly commented example...
Let me know if you have any questions
Now, back to the "Question 4" topic....the best way I can explain how to do what you were attempting to do is with a highly commented example...
Code:
class Program
{
static void Main(string[] args)
{
// Read in our lines from the file.
string[] lines = System.IO.File.ReadAllLines(@"C:\Test.txt");
Console.WriteLine("what word would you like to translate?");
// Wait for user input
string toMatch = Console.ReadLine();
// We want to make a list not an array to store the results.
// Arrays are fixed in size, and we do not know how many matches
// will be returned. A List is a variable size and can grow in size
// if required.
List<string> results = new List<string>();
// Loop through each of the lines from the file.
foreach (string s in lines)
{
// If there is no match found, we can just continue to the next line
// There are 2 ways to do this you can either check for a match and if successful
// add to the results list... or do as I have done here and move on.
// I tend to have most of my if statements be a line of defence for the unwanted...
// In this case we want a match, and if we don't have one, we move on. This avoids heavy nesting when
// writing complex functionality and quite a good habbit to get into.
if (!Regex.IsMatch(s, toMatch, RegexOptions.IgnoreCase))
{
continue;
}
// A match was found above, so we save that match to the results list.
results.Add(s);
}
// Output some statistical data.
Console.WriteLine("{0} matchs for '{1}' found", results.Count, toMatch);
// Loop through the results
foreach (string result in results)
{
// Display them to the screen
Console.WriteLine(result);
}
Console.WriteLine("Press any key to exit...");
Console.Read();
}
}