You could use an appropriate CompareInfo
and then CompareInfo.IndexOf(string, string, CompareOptions)
and check the result against -1. Sample:
using System;
using System.Globalization;
class Program
{
static void Main()
{
var compareInfo = CultureInfo.InvariantCulture.CompareInfo;
var options = CompareOptions.IgnoreCase |
CompareOptions.IgnoreSymbols |
CompareOptions.IgnoreNonSpace;
var haystack = "bla Lé OnAr d/o bla";
var needle = "leonardo";
var index = compareInfo.IndexOf(haystack, needle, options);
Console.WriteLine(index); // 4
}
}
Or in method form:
private static bool ComplexContains(string source, string value)
{
var index = CultureInfo.InvariantCulture.CompareInfo.IndexOf
(source, value, CompareOptions.IgnoreCase |
CompareOptions.IgnoreSymbols | CompareOptions.IgnoreNonSpace);
return index != -1;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…