Ok, I can certainly do this with some IndexOf, or even a Split(), but I thought I’d throw this out as a bit of a performance teaser.
I have data – like 100K’s of these – in LastName,FirstName Mi and I need to make it FirstName Mi Lastname.
I think that SubString/IndexOf(‘,’) can do the job, but was hoping for a more elegant/performant suggestion.
Any better ideas?
.Split is probably the fastest/most concise. However .IndexOf is surprisingly the fastest in small tests for this case (where we can rely on two commas and use LastIndexOf).
Paste the code below into LINQPad to test for yourself:
For 10,000,000 results (best indicator as early results could be highly variable) I get:
For 1,000,000 results I get:
For 100,000 results I get: