Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

C# String Like

Posted on March 15, 2014October 26, 2015 By David Kittell

I had a need to find a string like function similar to MSSQL and found this useful function.

public static bool StringLike(this string toSearch, string toFind)
{
return new Regex(@"A" + new Regex(@".|$|^|{|[|(|||)|*|+|?|").Replace(toFind, ch => @"" + ch).Replace('_', '.').Replace("%", ".*") + @"z", RegexOptions.Singleline).IsMatch(toSearch);
}
bool willBeTrue = StringLike("abcdefg","abcd_fg");
bool willAlsoBeTrue = StringLike("abcdefg","ab%f%");
bool willBeFalse = StringLike("abcdefghi","abcd_fg");

Reference: http://stackoverflow.com/questions/5417070/c-sharp-version-of-sql-like

Originally Posted on March 15, 2014
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code CSharp

Post navigation

Previous post
Next post

Related Posts

Delphix Web API – PowerShell Run Masking Job

Posted on April 19, 2018

Take note of the Global Variables $BaseURL and $LogFilePath, make sure you set them to your values. The idea for this script is to run this as part of a database restore/migration. Drop all access to the database to do the restore/migration, then run the script for Delphix, and then…

Read More

PHP – WordPress – Blog Info

Posted on February 16, 2016

This is a simple piece of code to provide basic information about your blog. The first lines of the code will restrict the PHP access to the command line interface (CLI) so not just anyone could/should be able to see the details. Additional Mime Types can be seen at: http://codex.wordpress.org/Function_Reference/get_allowed_mime_types…

Read More

Mac OSX Terminal – Change/Set DNS

Posted on May 27, 2016June 4, 2020

This may need to change depending on your network interface Manual Process # Only friendly names networksetup -listallnetworkservices # Useful information networksetup -listallhardwareports Running the above will display something like this An asterisk (*) denotes that a network service is disabled. Ethernet FireWire Wi-Fi Bluetooth PAN Thunderbolt Bridge # Optional…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes