mirror of
https://github.com/markjprice/cs11dotnet7.git
synced 2025-12-06 05:32:03 +01:00
Initial commit
This commit is contained in:
parent
143e708681
commit
5d934d40d6
|
|
@ -0,0 +1,10 @@
|
||||||
|
using System.Text.RegularExpressions; // [GeneratedRegex]
|
||||||
|
|
||||||
|
partial class Program
|
||||||
|
{
|
||||||
|
[GeneratedRegex(digitsOnlyText)]
|
||||||
|
private static partial Regex DigitsOnly();
|
||||||
|
|
||||||
|
[GeneratedRegex(commaSeparatorText)]
|
||||||
|
private static partial Regex CommaSeparator();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
using System.Diagnostics.CodeAnalysis; // [StringSyntax]
|
||||||
|
|
||||||
|
partial class Program
|
||||||
|
{
|
||||||
|
[StringSyntax(StringSyntaxAttribute.DateTimeFormat)]
|
||||||
|
const string fullDateTime = "dddd, d MMMM yyyy";
|
||||||
|
|
||||||
|
[StringSyntax(StringSyntaxAttribute.Regex)]
|
||||||
|
const string digitsOnlyText = @"^\d+$";
|
||||||
|
|
||||||
|
[StringSyntax(StringSyntaxAttribute.Regex)]
|
||||||
|
const string commaSeparatorText =
|
||||||
|
"(?:^|,)(?=[^\"]|(\")?)\"?((?(1)[^\"]*|[^,\"]*))\"?(?=,|$)";
|
||||||
|
}
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
Write("Enter your age: ");
|
Write("Enter your age: ");
|
||||||
string input = ReadLine()!; // null-forgiving
|
string input = ReadLine()!; // null-forgiving
|
||||||
|
|
||||||
Regex ageChecker = new(@"^\d+$");
|
Regex ageChecker = DigitsOnly();
|
||||||
|
|
||||||
if (ageChecker.IsMatch(input))
|
if (ageChecker.IsMatch(input))
|
||||||
{
|
{
|
||||||
|
|
@ -32,8 +32,7 @@ foreach (string film in filmsDumb)
|
||||||
WriteLine(film);
|
WriteLine(film);
|
||||||
}
|
}
|
||||||
|
|
||||||
Regex csv = new(
|
Regex csv = CommaSeparator();
|
||||||
"(?:^|,)(?=[^\"]|(\")?)\"?((?(1)[^\"]*|[^,\"]*))\"?(?=,|$)");
|
|
||||||
|
|
||||||
MatchCollection filmsSmart = csv.Matches(films);
|
MatchCollection filmsSmart = csv.Matches(films);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
using System.Text.RegularExpressions; // [GeneratedRegex]
|
||||||
|
|
||||||
|
partial class Program
|
||||||
|
{
|
||||||
|
[GeneratedRegex(digitsOnlyText)]
|
||||||
|
private static partial Regex DigitsOnly();
|
||||||
|
|
||||||
|
[GeneratedRegex(commaSeparatorText)]
|
||||||
|
private static partial Regex CommaSeparator();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
using System.Diagnostics.CodeAnalysis; // [StringSyntax]
|
||||||
|
|
||||||
|
partial class Program
|
||||||
|
{
|
||||||
|
[StringSyntax(StringSyntaxAttribute.DateTimeFormat)]
|
||||||
|
const string fullDateTime = "dddd, d MMMM yyyy";
|
||||||
|
|
||||||
|
[StringSyntax(StringSyntaxAttribute.Regex)]
|
||||||
|
const string digitsOnlyText = @"^\d+$";
|
||||||
|
|
||||||
|
[StringSyntax(StringSyntaxAttribute.Regex)]
|
||||||
|
const string commaSeparatorText =
|
||||||
|
"(?:^|,)(?=[^\"]|(\")?)\"?((?(1)[^\"]*|[^,\"]*))\"?(?=,|$)";
|
||||||
|
}
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
Write("Enter your age: ");
|
Write("Enter your age: ");
|
||||||
string input = ReadLine()!; // null-forgiving
|
string input = ReadLine()!; // null-forgiving
|
||||||
|
|
||||||
Regex ageChecker = new(@"^\d+$");
|
Regex ageChecker = DigitsOnly();
|
||||||
|
|
||||||
if (ageChecker.IsMatch(input))
|
if (ageChecker.IsMatch(input))
|
||||||
{
|
{
|
||||||
|
|
@ -32,8 +32,7 @@ foreach (string film in filmsDumb)
|
||||||
WriteLine(film);
|
WriteLine(film);
|
||||||
}
|
}
|
||||||
|
|
||||||
Regex csv = new(
|
Regex csv = CommaSeparator();
|
||||||
"(?:^|,)(?=[^\"]|(\")?)\"?((?(1)[^\"]*|[^,\"]*))\"?(?=,|$)");
|
|
||||||
|
|
||||||
MatchCollection filmsSmart = csv.Matches(films);
|
MatchCollection filmsSmart = csv.Matches(films);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue