// Use string interpolation to concatenate strings.
string str = $"Hello {userName}. Today is {date}.";
string[] words = { "The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog." };
var unreadablePhrase = string.Concat(words);
System.Console.WriteLine(unreadablePhrase);
var readablePhrase = string.Join(" ", words);
System.Console.WriteLine(readablePhrase);
// For user input and strings that will be displayed to the end user,
// use the StringComparison parameter on methods that have it to specify how to match strings.
bool ignoreCaseSearchResult = factMessage.StartsWith("extension", System.StringComparison.CurrentCultureIgnoreCase);
string[] numbers =
{ "123-555-0190", "444-3-2450", "690-555-0178", "146-893-232", "146-555-0122", "4007-555-0111", "407-555-0111", "407-2-5555", "407-555-8974", "407-2ab-5555", "690-555-8148", "146-893-232-" };
string sPattern = "^\\d{3}-\\d{3}-\\d{4}$";
foreach (string s in numbers)
{
Console.Write($"{s,14}");
if (System.Text.RegularExpressions.Regex.IsMatch(s, sPattern))
{
Console.WriteLine(" - valid");
}
else
{
Console.WriteLine(" - invalid");
}
}
^ matches the beginning of the string
\d{3} matches exactly 3 digit characters
- matches the '-' character
\d{4} matches exactly 4 digit characters
$ matches the end of the string