From cd0095e3c6a63da7f2452ec307847962bf50087b Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Sun, 15 Sep 2024 14:30:33 +0100 Subject: [PATCH] Use ReadOnlySpan.Split() (#557) - Treat some strings as spans and use their `Split()` method. - Use `string.Join(char)`. - Rename variable to theta symbol. --- src/ProjectEuler/Puzzles/Puzzle042.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/ProjectEuler/Puzzles/Puzzle042.cs b/src/ProjectEuler/Puzzles/Puzzle042.cs index ddf984fc..58fe7474 100644 --- a/src/ProjectEuler/Puzzles/Puzzle042.cs +++ b/src/ProjectEuler/Puzzles/Puzzle042.cs @@ -51,17 +51,16 @@ internal IList ReadWords() using var stream = ReadResource(); using var reader = new StreamReader(stream); - string rawWords = reader.ReadToEnd(); + var text = reader.ReadToEnd().AsSpan(); + var words = new List(); - string[] split = rawWords.Split(','); - - var words = new List(split.Length); - - foreach (string word in split) + foreach (var word in text.Split(',')) { - words.Add(word.Trim('\"')); + words.Add(text[word].Trim('\"').ToString()); } + words.TrimExcess(); + return words; }