[Solved] How do I find a substring in a string? [closed]


Contains is too slow for large numbers of data, plus it matches the domain and the in-the-middle occurences as well.

So use StartsWith

System.Data.DataTable dt = //Whatever
foreach(System.Data.DataRow dr in dt.Rows)
{
    //string email = dr("email");
    string email = "[email protected]";

    if (email != null && email.StartsWith("companyby", StringComparison.OrdinalIgnoreCase)) {
        // do whatever here
    }
}

With Linq:

var filteredList = IEnumerable<Emails>.Where(email =>  email != null ? email.StartsWith("companyby", StringComparison.OrdinalIgnoreCase) : false)

For Linq, you need to have .NET Framework > 3.0 and you need to add

using System.Data;
using System.Linq;

Because in there are extension methods.

3

solved How do I find a substring in a string? [closed]