ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

Like SQL on C#

An C# extension method based on "LIKE" operator of T-SQL.

Source

public static class StringExtensions
{
	public static bool Like(this string value, string search)
	{
		return value.Contains(search) || value.StartsWith(search) || value.EndsWith(search);
	}
}

Example

using System;
using System.Collections.Generic;

					
public class Program
{
	public static void Main()
	{
		string stringValue = "the brown fox jumped over the lazy dog";
		string searchCondition = "fox";
		
		Console.WriteLine(stringValue.Like(searchCondition));
//Will Return True
	}
}

Author: Rafael Tadeu Bezerra Faria

Submitted on: 29 jun. 2018

Language: C#

Type: object

Views: 5746