Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
On my side the regex code is twice as slow as a for loop (2526 ms vs 1149 ms).
Thanks better late than never on the reply :)
I have tested it and it is correct here and in other solutions too)
I do a foreach loop for 1_000_000 repetitions of the "yacht is the sea with a man in the sky" line discussed above, and compare it to regex.
Results:
1280 ms - for loop
1137 ms - regex
the for loop loses an average of 100 ms. LINQ is slower - 1809 ms
Summary: regex is the fastest and most obvious - really best practice)))
This comment is hidden because it contains spoiler information about the solution
I agree.
I would replace
str
with
str ?? ""
assuming that it can be possible to receive a null value, ex. a failure in reading a troll's comment...
I'm coming from Javascript. How C # is different. I will have to study hard. JS is very abstract, but C # ... I will suffer a little, but I like it.
For such simple algorithms, I would argue the opposite as best practise: for loop > LINQ > Regex
Regex is overkill for anything.
If it's a very simple parse, like this, you'll get better performance and code that's easier to read by just writing it out imperatively. If it's a complicated parse, you'll be less likely to run into bugs, and have code that's easier to read, by using a proper parser DSL such as ANTLR. Regex isn't particularly good at either case, and its complexlity is extremely high. The "now you have two problems" joke exists for a reason.
Trim replaces the spaces only in the beginning or end of a string. It combines "TrimStart" and "TrimEnd".
What is better for performance, built-in string methods or Regex engine?
I thought Trim erase all spaces!, Does this only trim the two sides?
gave this a bestPractice ... but how would I know? I am beginner... is it BP?
penetrating
Is regex an overkill for this one? Just asking because I'm not really familiar with regex.
Loading more items...