Skip to content

Commit

Permalink
Use ReadOnlySpan<char>.Split() (#557)
Browse files Browse the repository at this point in the history
- Treat some strings as spans and use their `Split()` method.
- Use `string.Join(char)`.
- Rename variable to theta symbol.
  • Loading branch information
martincostello committed Oct 17, 2024
1 parent b509be1 commit cd0095e
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/ProjectEuler/Puzzles/Puzzle042.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,16 @@ internal IList<string> 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>();

string[] split = rawWords.Split(',');

var words = new List<string>(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;
}

Expand Down

0 comments on commit cd0095e

Please sign in to comment.