The second option really isn't the same as the others - if the string is "///foo" it will become "foo" instead of "//foo".
The first option needs a bit more work to understand than the third - I would view the Substring
option as the most common and readable.
(Obviously each of them as an individual statement won't do anything useful - you'll need to assign the result to a variable, possibly data
itself.)
I wouldn't take performance into consideration here unless it was actually becoming a problem for you - in which case the only way you'd know would be to have test cases, and then it's easy to just run those test cases for each option and compare the results. I'd expect Substring
to probably be the fastest here, simply because Substring
always ends up creating a string from a single chunk of the original input, whereas Remove
has to at least potentially glue together a start chunk and an end chunk.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…