本文整理汇总了C#中System.StringComparison类的典型用法代码示例。如果您正苦于以下问题:C# StringComparison类的具体用法?C# StringComparison怎么用?C# StringComparison使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringComparison类属于System命名空间,在下文中一共展示了StringComparison类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WildcardPathSegment
public WildcardPathSegment(string beginsWith, List<string> contains, string endsWith, StringComparison comparisonType)
{
BeginsWith = beginsWith;
Contains = contains;
EndsWith = endsWith;
_comparisonType = comparisonType;
}
示例2: SearchTermMatches
public static Expression<Func<EstablishmentUrl, bool>> SearchTermMatches(string term, StringMatchStrategy matchStrategy, StringComparison? stringComparison = null)
{
var textMatches =
TextMatches(term, matchStrategy, stringComparison).Expand()
;
var officialUrlMatches =
IsOfficialUrl()
.And
(
textMatches
)
;
var nonOfficialNameMatches =
IsNotOfficialUrl()
//.And
//(
// TranslationToLanguageMatchesCurrentUiCulture()
//)
.And
(
textMatches
)
.Expand()
;
var urlMatches =
officialUrlMatches
.Or
(
nonOfficialNameMatches
)
;
return urlMatches;
}
示例3: CalculateCloseness
public static int? CalculateCloseness(this ILocation locationA, ILocation locationB, StringComparison comparisonType = StringComparison.InvariantCultureIgnoreCase)
{
var sequenceA = locationA.GetParts();
var sequenceB = locationB.GetParts();
return sequenceA.CalculateCloseness(sequenceB, comparisonType);
}
示例4: MakeUnique
public static void MakeUnique(ref List<string> items, StringComparison sc)
{
List<int> IndicesToRemove = new List<int>();
int index = 0;
foreach (string s in items)
{
if (index > 0)
{
if (ExistsInSubset(items, index, s, sc))
{
IndicesToRemove.Add(index);
}
}
++index;
}
if (IndicesToRemove.Count > 0)
{
for (index = IndicesToRemove.Count - 1; index >= 0; --index)
{
items.RemoveAt(IndicesToRemove[index]);
}
}
}
示例5: ContainsExt
public static bool ContainsExt(this string text, string toFind, StringComparison comparison)
{
if (text == null) { throw new ArgumentNullException(nameof(text)); }
if (toFind == null) { throw new ArgumentNullException(nameof(toFind)); }
return text.IndexOf(toFind, comparison) > -1;
}
示例6: Contains
/// <summary>
/// Determines whether a string contans another string.
/// </summary>
public static bool Contains(this string source, string value, StringComparison compareMode)
{
if (string.IsNullOrEmpty(source))
return false;
return source.IndexOf(value, compareMode) >= 0;
}
示例7: ContainsAny
/// <summary>
/// Checks if the string contains any of the values given.
/// </summary>
/// <exception cref="ArgumentNullException">The string can not be null.</exception>
/// <exception cref="ArgumentNullException">The values can not be null.</exception>
/// <param name="str">The string to check.</param>
/// <param name="values">The values to search for.</param>
/// <param name="comparisonType">The string comparison type.</param>
/// <returns>Returns true if the string contains any of the values given, otherwise false.</returns>
public static Boolean ContainsAny( this String str, StringComparison comparisonType, params String[] values )
{
str.ThrowIfNull( nameof( str ) );
values.ThrowIfNull( nameof( values ) );
return values.Any( x => str.IndexOf( x, comparisonType ) != -1 );
}
示例8: Contains
public static bool Contains(this string input, string value, StringComparison comparisonType)
{
if (input.DoesNotHaveValue())
return false;
return input.IndexOf(value, comparisonType) >= 0;
}
示例9: StringLiteralSearchComparer
public StringLiteralSearchComparer(string s, bool caseSensitive = false, bool matchWholeString = false) {
if (s == null)
throw new ArgumentNullException();
this.str = s;
this.stringComparison = caseSensitive ? StringComparison.InvariantCulture : StringComparison.InvariantCultureIgnoreCase;
this.matchWholeString = matchWholeString;
}
示例10: Contains
/// <summary>
/// Returns true if a string contains a substring, using the specified StringComparison.
/// </summary>
public static bool Contains (this string s, string value, StringComparison sc)
{
CompareOptions co;
switch (sc) {
case StringComparison.CurrentCulture:
co = CompareOptions.None;
break;
case StringComparison.CurrentCultureIgnoreCase:
co = CompareOptions.IgnoreCase;
break;
case StringComparison.InvariantCulture:
co = CompareOptions.None;
break;
case StringComparison.InvariantCultureIgnoreCase:
co = CompareOptions.IgnoreCase;
break;
case StringComparison.Ordinal:
co = CompareOptions.Ordinal;
break;
case StringComparison.OrdinalIgnoreCase:
co = CompareOptions.OrdinalIgnoreCase;
break;
default:
throw new InvalidOperationException ("Unknown string comparison value.");
}
return s.Contains (value, sc.RelatedCulture (), co);
}
示例11: Validate
/// <summary>
/// Validates the specified <paramref name="value"/> and throws an <see cref="ArgumentException"/>
/// exception if not valid.
/// </summary>
/// <param name="value">The value to validate.</param>
/// <param name="parameterName">Name of the parameter to use if throwing exception.</param>
public static void Validate(StringComparison value, string parameterName)
{
if (!IsDefined(value))
{
throw Error.InvalidEnumArgument(parameterName, (int)value, typeof(StringComparison));
}
}
示例12: GetTrailsAndinjectValue
public static IEnumerable<Queue<string>> GetTrailsAndinjectValue(PropertyWithComponent target, PropertyWithComponent source, Predicate<Type> f, Queue<string> root, StringComparison comparison)
{
if (string.Equals(target.Property.Name, source.Property.Name, comparison) && f(source.Property.PropertyType))
{
var queue = new Queue<string>();
queue.Enqueue(source.Property.Name);
source.Property.SetValue(target.Component, source.Property.GetValue(source.Component, null), null);
yield return queue;
yield break;
}
if (target.Property.Name.StartsWith(source.Property.Name, comparison))
{
root.Enqueue(source.Property.Name);
foreach (var pro in source.Property.PropertyType.GetInfos())
{
foreach (var trail in GetTrails(target.Property.Name.RemovePrefix(source.Property.Name, comparison), pro, f, root, comparison))
{
var queue = new Queue<string>();
queue.Enqueue(source.Property.Name);
foreach (var value in trail.Reverse())
{
queue.Enqueue(value);
}
yield return queue;
}
}
}
}
示例13: GetTrails
public static IEnumerable<Queue<string>> GetTrails(string upn, PropertyInfo prop, Predicate<Type> f, Queue<string> root, StringComparison comparison)
{
if (string.Equals(upn, prop.Name, comparison) && f(prop.PropertyType))
{
var queue = new Queue<string>();
queue.Enqueue(prop.Name);
yield return queue;
yield break;
}
if (upn.StartsWith(prop.Name, comparison))
{
root.Enqueue(prop.Name);
foreach (var pro in prop.PropertyType.GetInfos())
{
foreach (var trail in GetTrails(upn.RemovePrefix(prop.Name, comparison), pro, f, root, comparison))
{
var queue = new Queue<string>();
queue.Enqueue(prop.Name);
foreach (var value in trail)
{
queue.Enqueue(value);
}
yield return queue;
}
}
}
}
示例14: GetTrails
public static IEnumerable<IList<string>> GetTrails(string upn, PropertyInfo prop, Func<string, PropertyInfo, bool> match, IList<string> root, StringComparison comparison, bool flat = true)
{
if (flat && !prop.CanRead || !flat && !prop.CanWrite)
{
yield return null;
yield break;
}
if (match(upn, prop))
{
var l = new List<string> { prop.Name };
yield return l;
yield break;
}
if (upn.StartsWith(prop.Name, comparison))
{
root.Add(prop.Name);
foreach (var pro in prop.PropertyType.GetProps())
{
foreach (var trail in GetTrails(upn.RemovePrefix(prop.Name, comparison), pro, match, root, comparison, flat))
{
if (trail != null)
{
var r = new List<string> { prop.Name };
r.AddRange(trail);
yield return r;
}
}
}
}
}
示例15: AsciiEquivalentMatches
private static Expression<Func<PlaceName, bool>> AsciiEquivalentMatches(string term, StringMatchStrategy matchStrategy, StringComparison? stringComparison = null)
{
Expression<Func<PlaceName, bool>> expression;
switch (matchStrategy)
{
case StringMatchStrategy.Equals:
if (stringComparison.HasValue)
expression = name => name.AsciiEquivalent.Equals(term, stringComparison.Value);
else
expression = name => name.AsciiEquivalent.Equals(term);
break;
case StringMatchStrategy.StartsWith:
if (stringComparison.HasValue)
expression = name => name.AsciiEquivalent.StartsWith(term, stringComparison.Value);
else
expression = name => name.AsciiEquivalent.StartsWith(term);
break;
case StringMatchStrategy.Contains:
if (stringComparison.HasValue)
expression = name => name.AsciiEquivalent.Contains(term, stringComparison.Value);
else
expression = name => name.AsciiEquivalent.Contains(term);
break;
default:
throw new NotSupportedException(string.Format("StringMatchStrategy '{0}' is not supported.", matchStrategy));
}
return AsciiEquivalentIsNotNull().And(expression).Expand();
}