5

String Performance: Checking for a Substring – dotNetTips.com

 2 years ago
source link: https://dotnettips.wordpress.com/2021/11/09/string-performance-checking-for-a-substring/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK