本文整理汇总了C#中this.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# this.Contains方法的具体用法?C# this.Contains怎么用?C# this.Contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类this
的用法示例。
在下文中一共展示了this.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Intersects
public static bool Intersects(this ITimeInterval time1, ITimeInterval time2)
{
return
time1 != null && time2 != null &&
(time1.Contains(time2.From) ||
time1.Contains(time2.To));
}
示例2: ToStringArray
/// <summary>
/// Converts <paramref name="folderStructureOptions"/> to string array
/// </summary>
/// <param name="folderStructureOptions">Folder structure retrieve options</param>
/// <returns>String array representation of <paramref name="folderStructureOptions"/></returns>
public static string[] ToStringArray(this RetrieveFolderStructureOptions folderStructureOptions)
{
List<string> result = new List<string>(3);
if(folderStructureOptions.Contains(RetrieveFolderStructureOptions.NoFiles))
{
result.Add("nofiles");
}
if (folderStructureOptions.Contains(RetrieveFolderStructureOptions.NoZip))
{
result.Add("nozip");
}
if (folderStructureOptions.Contains(RetrieveFolderStructureOptions.OneLevel))
{
result.Add("onelevel");
}
if (folderStructureOptions.Contains(RetrieveFolderStructureOptions.Simple))
{
result.Add("simple");
}
return result.ToArray();
}
示例3: HasRouteKey
public static bool HasRouteKey(this string routeUrl, string routeKey)
{
return
routeUrl.Contains("{" + routeKey + "}")
||
routeUrl.Contains("{" + "*" + routeKey + "}");
}
示例4: GetDoubleValueFromStringEntry
public static double GetDoubleValueFromStringEntry(this string val)
{
// Todo, felkollar
var cultureToUse = System.Threading.Thread.CurrentThread.CurrentCulture;
if (string.IsNullOrEmpty(val))
{
return 0.0;
}
if (val.Contains("."))
{
cultureToUse = new CultureInfo("en-US");
}
else if (val.Contains(","))
{
cultureToUse = new CultureInfo("sv-SE");
}
var cleanVal = val.Trim()
.Replace(" ", string.Empty)
.Replace(":", string.Empty)
.Replace(";", string.Empty)
.Replace(":", string.Empty);
double tempd;
return double.TryParse(cleanVal, NumberStyles.Number, cultureToUse, out tempd)
? Math.Round(tempd, 2)
: 0.0;
}
示例5: GetStringBetween
public static string GetStringBetween(
this string input, string startString, string endString, int startFrom = 0)
{
input = input.Substring(startFrom);
startFrom = 0;
if (!input.Contains(startString) || !input.Contains(endString))
{
return string.Empty;
}
var startPosition =
input.IndexOf(startString, startFrom, StringComparison.Ordinal) + startString.Length;
if (startPosition == -1)
{
return string.Empty;
}
var endPosition = input.IndexOf(endString, startPosition, StringComparison.Ordinal);
if (endPosition == -1)
{
return string.Empty;
}
return input.Substring(startPosition, endPosition - startPosition);
}
示例6: RemoveBetween
/// <summary>
/// http://stackoverflow.com/a/39096603/128662
/// </summary>
public static string RemoveBetween(this string rawString, char enter, char exit)
{
if (rawString.Contains(enter) && rawString.Contains(exit))
{
int substringStartIndex = rawString.IndexOf(enter) + 1;
int substringLength = rawString.LastIndexOf(exit) - substringStartIndex;
string replaced = rawString;
if (substringLength > 0 && substringLength > substringStartIndex)
{
string substring = rawString.Substring(substringStartIndex, substringLength).RemoveBetween(enter, exit);
if (substring.Length != substringLength) // This would mean that letters have been removed
{
replaced = rawString.Remove(substringStartIndex, substringLength).Insert(substringStartIndex, substring);
}
}
//Source: http://stackoverflow.com/a/1359521/3407324
Regex regex = new Regex(string.Format("\\{0}.*?\\{1}", enter, exit));
return new Regex(" +").Replace(regex.Replace(replaced, string.Empty), " ");
}
else
{
return rawString;
}
}
示例7: Contains
public static bool Contains(this Rect rect, Rect otherRect)
{
Vector2 topLeftPoint = new Vector2(otherRect.xMin, otherRect.yMin);
Vector2 bottomRightPoint = new Vector2(otherRect.xMax, otherRect.yMax);
//Debug.Log("Rect " + new Vector2(rect.xMax, rect.yMax) + " topLeftPoint " + topLeftPoint + " bottomRightPoint " + bottomRightPoint);
return rect.Contains(topLeftPoint) && rect.Contains(bottomRightPoint);
}
示例8: StemNameBase
public static string StemNameBase(this string name)
{
if (name == null) {
throw new ArgumentNullException("name");
}
if (!name.Contains(" ")) {
name = name.Replace('_', ' ');
if (!name.Contains(" ")) {
name = name.Replace('-', ' ');
}
name = respace.Replace(name, " ");
}
var ws = name;
var wsprev = name;
do {
wsprev = ws;
ws = trim.Replace(wsprev.Trim(), " ").Trim();
}
while (wsprev != ws);
if (string.IsNullOrWhiteSpace(ws)) {
return name;
}
return ws;
}
示例9: parseRow
public static dynamic parseRow(this string matchString, string[] columns)
{
var defaults = new Dictionary<string, string>()
{
{"Event", "Open Play"},
{"Location", "Courtyard"},
{"Club", "Courtyard"},
{"Time", "6am"},
{"Comments", ""},
};
var delimiter = matchString.Contains("\t") ? "\t" : matchString.Contains(",") ? "," : " ";
var array = matchString.Split(delimiter.ToCharArray(), StringSplitOptions.None);
//var values = new Dictionary<string, string>();
dynamic expando = new ExpandoObject();
var values = (IDictionary<string, object>)expando;
for (int i = 0; i < array.Length; i++)
{
var key = columns[i];
var value = array[i];
if (value == "")
value = defaults[key];
values.Add(key, value);
}
return values;
}
示例10: ToCellType
public static CellType ToCellType(this string battleType)
{
return battleType.Contains("sp_midnight") ? CellType.夜戦
: battleType.Contains("ld_airbattle") ? CellType.空襲戦 //ColorNoからも分かるが、航空戦と誤認しないため
: battleType.Contains("airbattle") ? CellType.航空戦
: CellType.None;
}
示例11: IsBase64
public static bool IsBase64(this string base64String)
{
// Based on http://stackoverflow.com/a/6309439
// pre-test to check if it's obviously invalid
// (fast for long values like images and videos)
if (string.IsNullOrEmpty(base64String) ||
base64String.Length % 4 != 0 ||
base64String.Contains(" ") ||
base64String.Contains("\t") ||
base64String.Contains("\r") ||
base64String.Contains("\n"))
{
return false;
}
// now do the real test
try
{
Convert.FromBase64String(base64String);
return true;
}
catch (FormatException)
{
return false;
}
}
示例12: CompareTo
/// <summary>
/// Compares to the given value returning true if comparable.
/// </summary>
/// <param name="value">The value.</param>
/// <param name="compareValue">The compare value.</param>
/// <param name="compareType">Type of the compare.</param>
/// <returns></returns>
public static bool CompareTo( this string value, string compareValue, ComparisonType compareType )
{
// Evaluate compare types that are not type specific
switch ( compareType )
{
case ComparisonType.Contains: return value.Contains( compareValue );
case ComparisonType.DoesNotContain: return !value.Contains( compareValue );
case ComparisonType.StartsWith: return value.StartsWith( compareValue, StringComparison.OrdinalIgnoreCase );
case ComparisonType.EndsWith: return value.EndsWith( compareValue, StringComparison.OrdinalIgnoreCase );
case ComparisonType.IsBlank: return string.IsNullOrWhiteSpace( value );
case ComparisonType.IsNotBlank: return !string.IsNullOrWhiteSpace( value );
case ComparisonType.RegularExpression: return Regex.IsMatch( value, compareValue );
}
// numeric compares
decimal? decimalValue = value.AsDecimalOrNull();
decimal? decimalCompareValue = compareValue.AsDecimalOrNull();
if ( decimalValue.HasValue && decimalCompareValue.HasValue )
{
switch ( compareType )
{
case ComparisonType.EqualTo: return decimalValue == decimalCompareValue;
case ComparisonType.GreaterThan: return decimalValue.Value > decimalCompareValue.Value;
case ComparisonType.GreaterThanOrEqualTo: return decimalValue.Value >= decimalCompareValue.Value;
case ComparisonType.LessThan: return decimalValue.Value < decimalCompareValue.Value;
case ComparisonType.LessThanOrEqualTo: return decimalValue.Value <= decimalCompareValue.Value;
case ComparisonType.NotEqualTo: return decimalValue.Value != decimalCompareValue.Value;
}
}
// date time compares
DateTime? datetimeValue = value.AsDateTime();
DateTime? datetimeCompareValue = compareValue.AsDateTime();
if ( datetimeValue.HasValue && datetimeCompareValue.HasValue )
{
switch ( compareType )
{
case ComparisonType.EqualTo: return datetimeValue == datetimeCompareValue;
case ComparisonType.GreaterThan: return datetimeValue.Value > datetimeCompareValue.Value;
case ComparisonType.GreaterThanOrEqualTo: return datetimeValue.Value >= datetimeCompareValue.Value;
case ComparisonType.LessThan: return datetimeValue.Value < datetimeCompareValue.Value;
case ComparisonType.LessThanOrEqualTo: return datetimeValue.Value <= datetimeCompareValue.Value;
case ComparisonType.NotEqualTo: return datetimeValue.Value != datetimeCompareValue.Value;
}
}
// string compares
switch ( compareType )
{
case ComparisonType.EqualTo: return value.Equals( compareValue, StringComparison.OrdinalIgnoreCase );
case ComparisonType.GreaterThan: return value.CompareTo( compareValue ) > 0;
case ComparisonType.GreaterThanOrEqualTo: return value.CompareTo( compareValue ) >= 0;
case ComparisonType.LessThan: return value.CompareTo( compareValue ) < 0;
case ComparisonType.LessThanOrEqualTo: return value.CompareTo( compareValue ) <= 0;
case ComparisonType.NotEqualTo: return !value.Equals( compareValue, StringComparison.OrdinalIgnoreCase );
}
return false;
}
示例13: SubstringRange
public static string SubstringRange(this string s, char start, char end)
{
if (s.Contains(start) && s.Contains(end))
{
return s.Substring(s.IndexOf(start), s.IndexOf(end) - s.IndexOf(start) + 1);
}
else return "";
}
示例14: RemoveRange
public static string RemoveRange(this string s, char start, char end)
{
if (s.Contains(start) && s.Contains(end))
{
return s.Remove(s.IndexOf(start), s.IndexOf(end) - s.IndexOf(start) + 1);
}
else return s;
}
示例15: IntersectsLine
public static bool IntersectsLine( this Rect r, Vector2 p1, Vector2 p2 )
{
return LineIntersectsLine ( p1, p2, new Vector2 ( r.x, r.y ), new Vector2 ( r.x + r.width, r.y ) ) ||
LineIntersectsLine ( p1, p2, new Vector2 ( r.x + r.width, r.y ), new Vector2 ( r.x + r.width, r.y + r.height ) ) ||
LineIntersectsLine ( p1, p2, new Vector2 ( r.x + r.height, r.y + r.height ), new Vector2 ( r.x, r.y + r.height ) ) ||
LineIntersectsLine ( p1, p2, new Vector2 ( r.x, r.y + r.height ), new Vector2 ( r.x, r.y ) ) ||
( r.Contains ( p1 ) && r.Contains ( p2 ) );
}