String Performance: Checking for a Substring

There are three main methods to check for a string, within a string. Those methods, from String, are:

  • Contains()
  • StartsWith()
  • EndsWith()

Here is an example of how to use Contains().

bool result = "David McCarter".Contains("David");

Benchmark Results

These results are for your own information when using these methods. For more information about checking for a substring, see the Internationalization and Localization articles.

Checking for a Substring Chart

Pick up any books by David McCarter by going to Amazon.com: http://bit.ly/RockYourCodeBooks

© The information in this article is copywritten and cannot be preproduced in any way without express permission from David McCarter.


The benchmark results in this article are only for your reference. Your results will be different, so make sure to benchmark your code using Benchmarkdotnet.

One thought on “String Performance: Checking for a Substring

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.