This article is a mirror article of machine translation, please click here to jump to the original article.

View: 27326|Reply: 0

[Source] Use case-ignoring strings in C#. Contains method

[Copy link]
Posted on 6/20/2019 11:24:09 PM | | |
To compare whether the source string contains the target string in C#, we can use the following method:



Relatively speaking, the Contains method is more intuitive because it directly returns a boolean value, but when we need to ignore case, we can only use the IndexOf overload method that supports the StringComparison parameter, but this method may not be semantic enough (the return value may be -1, 0, or greater than 0), although in this case many people may convert both the source string and the target string to uppercase or lowercase for comparison, but this is too inefficient. We can directly define an extension that supports the StringComparison parameter:


In fact. NET library The Contains method is also based on the IndexOf method:


reference

The hyperlink login is visible.





Previous:C# listview control a cell color
Next:Use EF Core MySQL data migration operations in .NET Core
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com