

Strings Contain Empty Strings
source link: https://www.stevefenton.co.uk/2021/03/strings-contain-empty-strings/
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.

Strings Contain Empty Strings
This is just one of those philosophical moments in programming where one small details can have a big impact. In C# / .NET you will find that when you ask if a string contains an empty string (string.Empty
), the answer is yes. This may seem logically surprising so it is worth bearing in mind should you be comparing strings.
// True bool isMatch = "some string".Contains(string.Empty);
A more realistic example is below, imagine you have a config file with some value, and the value isn’t set for some environment… every comparison made will match.
private string GetItem(string item) { // True bool isMatch = item.Contains(_config.RudeWord); return isMatch ? string.Empty : item; }
Posted bySteve Fenton16th March 2021Posted inProgrammingTags:c#
Published by Steve Fenton
Recommend
-
99
除非特别声明,此文章内容采用知识共享署名 3.0许可,代码示例采用Apache 2.0许可。更多细节请查看我们的服务条款。
-
175
README.md ApfsSupportPkg
-
82
README.md itty.bitty.site itty.bitty takes html (or other data), compresses it into a URL fragment, and provides a link that can be shared. When it is opened, it inflates that data on the recie...
-
42
The Arch Linux user-maintained software repository called AUR has been found to host malware. The discovery was made after a change in one of the package installation instructions was made. This is yet another incident th...
-
35
Welcome to Snyk’s annual State of Open Source Security report 2019. This report is split into several posts: Maven Central packages double; a quart...
-
7
Conversation Copy link Contributor...
-
8
[Golang] Remove Leading and Trailing Empty Strings in String Array J...
-
8
Testing membership and empty strings By J. Ryan Hall on 20 January 2023 I was working on one of the exe...
-
15
This tutorial will discuss about unique ways to check if numpy array contains only empty strings. Table Of Contents Method 1: using numpy.char.str_len() The numpy
-
10
Check if Array Contains Only Empty Strings in C++ This tutorial will discuss about a unique way to check if array contains only empty strings in C++. Suppose we have a string array. Like this,
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK