Does anyone know if there's any performance difference between using these
two methods or in what circumstances you should use one over the other? For
instance if I want to cut off the first 10 characters in my string I could
use either
myString.Remove(0,10);
myString.Substring(11);

Thanks,

Janaka

Re: String.Remove vs String.Substring by Bogdan

Bogdan
Wed Nov 05 05:56:31 CST 2003

On 11/5/2003 11:58 AM, Janaka wrote:

> Does anyone know if there's any performance difference between using these
> two methods or in what circumstances you should use one over the other? For
> instance if I want to cut off the first 10 characters in my string I could
> use either
> myString.Remove(0,10);
> myString.Substring(11);

It's quite easy to check this. According to some benchmarks I've
performed Remove is about 40-50% slower than Substring.

regards
Bogdan


Re: String.Remove vs String.Substring by Cowboy

Cowboy
Wed Nov 05 08:59:22 CST 2003

Substring should be faster, as the method is basically saying, make a new
string starting at this point. With remove, you are asking it to evaluate
the first 10 characters and remove them to create the new string. Whether
the performance difference makes a difference is another story. It is
likely, unless you app is being hammered, that either method will make a
major difference in terms of perceived performance. As neither is easier to
maintain, I would opt for performance and use SubString instead.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
"Janaka" <janaka@magicalia.com> wrote in message
news:OddKKv4oDHA.3612@TK2MSFTNGP11.phx.gbl...
> Does anyone know if there's any performance difference between using these
> two methods or in what circumstances you should use one over the other?
For
> instance if I want to cut off the first 10 characters in my string I could
> use either
> myString.Remove(0,10);
> myString.Substring(11);
>
> Thanks,
>
> Janaka
>
>