String - GetBefore

A string extension method that get the string before the specified string.

Try it

public static void Main()
{
	string str = "EntityFramework";

	// C# Extension Method: String - GetBefore
    string getBeforeStr = str.GetBefore("Framework");
	
	Console.WriteLine(getBeforeStr);
}

View Source
public static partial class Extensions
{
    /// <summary>
    ///     A string extension method that get the string before the specified string.
    /// </summary>
    /// <param name="this">The @this to act on.</param>
    /// <param name="value">The value to search.</param>
    /// <returns>The string before the specified value.</returns>
    public static string GetBefore(this string @this, string value)
    {
        if (@this.IndexOf(value) == -1)
        {
            return "";
        }
        return @this.Substring(0, @this.IndexOf(value));
    }
}