/// <summary> /// Is this value of the specified type /// </summary> /// <param name="value">Value to compare</param> /// <param name="comparisonType">Comparison type</param> /// <returns>True if it is of the type specified, false otherwise</returns> public static bool Is(this string?value, StringCompare comparisonType) { if (string.IsNullOrEmpty(value)) { return(false); } if (comparisonType == StringCompare.CreditCard) { long CheckSum = 0; value = value.Replace("-", "", StringComparison.Ordinal).Reverse(); for (var x = 0; x < value.Length; ++x) { if (!value[x].Is(CharIs.Digit)) { return(false); } var Tempvalue = (value[x] - '0') * (x % 2 == 1 ? 2 : 1); while (Tempvalue > 0) { CheckSum += Tempvalue % 10; Tempvalue /= 10; } } return((CheckSum % 10) == 0); } if (comparisonType == StringCompare.Unicode) { return(string.IsNullOrEmpty(value) || IsUnicode.Replace(value, "") != value); } return(value.Is("", StringCompare.Anagram)); }
public void StringCompare_Methods_Equal() { var stringCompare = new StringCompare(); Assert.Equal(stringCompare.CompareStringByIndexOf(), stringCompare.CompareStringByStringEquals()); Assert.Equal(stringCompare.CompareStringByToLower(), stringCompare.CompareStringByStringEquals()); }
/// <summary> /// Returns the content of specified tag. /// </summary> /// <param name="pageHtml">html code</param> /// <param name="justTagName">The tag name like TABLE</param> public static string GetTagContent(ref string pageHtml, string justTagName) { string startTag = '<' + justTagName; string endTag = justTagName + '>'; int start, end; start = StringCompare.IndexOfIgnoreCase(ref pageHtml, startTag); if (start == -1) { return(""); } start = StringCompare.IndexOfMatchCase(ref pageHtml, '>', start); if (start == -1) { return(""); } start++; end = StringCompare.IndexOfIgnoreCase(ref pageHtml, endTag, start); if (end == -1) { return(""); } end = StringCompare.LastIndexOfMatchCase(ref pageHtml, '<', end); if (end == -1 || start > end) { return(""); } return(pageHtml.Substring(start, end - start).Trim()); }
/// <summary> /// Is this value of the specified type /// </summary> /// <param name="Value">Value to compare</param> /// <param name="ComparisonType">Comparison type</param> /// <returns>True if it is of the type specified, false otherwise</returns> public static bool Is(this string Value, StringCompare ComparisonType) { if (ComparisonType == StringCompare.CreditCard) { long CheckSum = 0; Value = Value.Replace("-", "").Reverse(); for (int x = 0; x < Value.Length; ++x) { if (!Value[x].Is(CharIs.Digit)) { return(false); } int TempValue = (Value[x] - '0') * (x % 2 == 1 ? 2 : 1); while (TempValue > 0) { CheckSum += TempValue % 10; TempValue /= 10; } } return((CheckSum % 10) == 0); } if (ComparisonType == StringCompare.Unicode) { return(string.IsNullOrEmpty(Value) || Regex.Replace(Value, @"[^\u0000-\u007F]", "") != Value); } return(Value.Is("", StringCompare.Anagram)); }
/// <summary> /// Is this value of the specified type /// </summary> /// <param name="Value1">Value 1 to compare</param> /// <param name="Value2">Value 2 to compare</param> /// <param name="ComparisonType">Comparison type</param> /// <returns>True if it is of the type specified, false otherwise</returns> public static bool Is(this string Value1, string Value2, StringCompare ComparisonType) { if (ComparisonType != StringCompare.Anagram) { return(Value1.Is(ComparisonType)); } return(new string(Value1.OrderBy(x => x).ToArray()) == new string(Value2.OrderBy(x => x).ToArray())); }
public void GetTextSimilarity_ShouldThrowArgumentNullException_WhenInputTwoIsNull() { // Arrange string inputOne = "test"; string inputTwo = null; // Act double actualSimilarity = StringCompare.GetTextSimilarity(inputOne, inputTwo); }
public static bool CompareString(string a, string b, StringCompare cm) { if (cm == AiGlobals.StringCompare.EqualTo) { return(a.ToLower() == b.ToLower()); } if (cm == AiGlobals.StringCompare.Contains) { //return a.ToLower().Contains(b.ToLower()); bool comparison = false; if (b.Contains(",")) { // check for multiple strings, any of which must be in target string[] theStrings = b.Split(','); foreach (string token in theStrings) { comparison = a.ToLower().Contains(token.ToLower()); if (comparison) { break; } } return(comparison); } else { return(a.ToLower().Contains(b.ToLower())); } } if (cm == AiGlobals.StringCompare.StartsWith) { return(a.ToLower().StartsWith(b.ToLower())); } if (cm == AiGlobals.StringCompare.DoesNotContain) { bool comparison = true; if (b.Contains(",")) { // check for multiple strings, all of which must not be in target string[] theStrings = b.Split(','); foreach (string token in theStrings) { comparison = !(a.ToLower().Contains(token.ToLower())); if (!comparison) { break; } } return(comparison); } else { return(!a.ToLower().Contains(b.ToLower())); } } return(false); }
/// <summary> /// Is this value of the specified type /// </summary> /// <param name="value1">Value 1 to compare</param> /// <param name="value2">Value 2 to compare</param> /// <param name="comparisonType">Comparison type</param> /// <returns>True if it is of the type specified, false otherwise</returns> public static bool Is(this string?value1, string value2, StringCompare comparisonType) { if (comparisonType != StringCompare.Anagram) { return(value1.Is(comparisonType)); } return(new string(value1?.ToCharArray().OrderBy(x => x).ToArray()) == new string(value2?.ToCharArray().OrderBy(x => x).ToArray())); }
public void Initialize() { bubbleSortInt = new BubbleClass <int>(); univCompareInt = new UnivCompare <int>(); bubbleSortString = new BubbleClass <string>(); univCompareStr = new UnivCompare <string>(); intCompare = new IntCompare(); stringCompare = new StringCompare(); stringCompare2 = new StringCompare2(); }
public void Initialize() { bubbleSortInt = new BubbleClass<int>(); univCompareInt = new UnivCompare<int>(); bubbleSortString = new BubbleClass<string>(); univCompareStr = new UnivCompare<string>(); intCompare = new IntCompare(); stringCompare = new StringCompare(); stringCompare2 = new StringCompare2(); }
/// <summary> /// Gets a value which indicates whether the <paramref name="name"/> is present in the model /// when searching the list indicated by <paramref name="isSeen"/>. /// </summary> /// <param name="name">Name of the beastie</param> /// <param name="isSeen"> /// Indicates whether the beastie is seen or heard. /// </param> /// <returns> /// Indicates whether the beastie is currently present. /// </returns> public bool GetIncluded( string name, bool isSeen) { if (isSeen) { return(this.observations.Species.Kind.Find(k => StringCompare.SimpleCompare(k, name)) != null); } return(this.observations.Heard.Kind.Find(k => StringCompare.SimpleCompare(k, name)) != null);; }
public override bool CheckExpectation(IWebDriver webDriver) { var matches = StringCompare.IsMatch(webDriver.Url, MatchType, Url); if (!matches) { Message = $"URL expected to be `{Url}` but was `{webDriver.Url}` (Match type: {MatchType})"; } return(matches); }
private int TagCompare(string?str1, string?str2) { if (str1 == null || str2 == null) { return(int.MaxValue); } return(StringCompare.LevensteinDistance( string.Join(" ", str1.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).OrderBy(name => name)), string.Join(" ", str2.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).OrderBy(name => name)) )); }
public void GetTextSimilarity_ShouldReturnQuarter_WhenInputsQuarterSame() { // Arrange string inputOne = "test"; string inputTwo = "txyz"; // Act double actualSimilarity = StringCompare.GetTextSimilarity(inputOne, inputTwo); // Assert Assert.AreEqual <double>(expected: 0.25, actual: actualSimilarity); }
public void GetTextSimilarity_ShouldReturnHalf_WhenInputsHalfSimilarAndSameLength() { // Arrange string inputOne = "tear"; string inputTwo = "test"; // Act double actualSimilarity = StringCompare.GetTextSimilarity(inputOne, inputTwo); // Assert Assert.AreEqual <double>(expected: 0.5, actual: actualSimilarity); }
public void GetTextSimilarity_ShouldReturnOne_WhenBothInputsEmpty() { // Arrange string inputOne = ""; string inputTwo = ""; // Act double actualSimilarity = StringCompare.GetTextSimilarity(inputOne, inputTwo); // Assert Assert.AreEqual <double>(expected: 1, actual: actualSimilarity); }
public static Expression <Func <string, bool> > GetStringCompareExpression(Expression parameter, Expression operand, ParameterExpression param, StringCompare compare, StringComparer comparer) { switch (compare) { case StringCompare.Equals: return(comparer == null ? Expression.Lambda <Func <string, bool> >(Expression.Equal(parameter, operand), param) : null); case StringCompare.NotEquals: return(comparer == null ? Expression.Lambda <Func <string, bool> >(Expression.NotEqual(parameter, operand), param) : null); case StringCompare.Contains: return(comparer == null ? Expression.Lambda <Func <string, bool> >(GetContainsExpression(parameter, operand), param) : null); case StringCompare.NotContains: return(comparer == null ? Expression.Lambda <Func <string, bool> >(GetNotContainsExpression(parameter, operand), param) : null); case StringCompare.RegexLike: return(null); case StringCompare.StartsWith: return(comparer == null ? Expression.Lambda <Func <string, bool> >(GetStartsWithExpression(parameter, operand), param) : null); case StringCompare.NotStartsWith: return(comparer == null ? Expression.Lambda <Func <string, bool> >(GetNotStartsWithExpression(parameter, operand), param) : null); case StringCompare.EndsWith: return(comparer == null ? Expression.Lambda <Func <string, bool> >(GetEndsWithExpression(parameter, operand), param) : null); case StringCompare.NotEndsWith: return(comparer == null ? Expression.Lambda <Func <string, bool> >(GetNotEndsWithExpression(parameter, operand), param) : null); default: throw new ArgumentOutOfRangeException(nameof(compare), compare, null); } }
/// <summary> /// Select a new page for the view. /// </summary> /// <param name="newPageName"> /// Name of the page to display. /// </param> private void NewPage(string newPageName) { if (StringCompare.SimpleCompare(newPageName, ConfigureBeastie)) { if (this.CurrentWorkspace.GetType() != typeof(BeastieConfigurationViewModel)) { this.CurrentWorkspace = new BeastieConfigurationViewModel( this.dataManager, this.fileFactory); this.RaisePropertyChangedEvent(nameof(this.CurrentWorkspace)); } } }
public static string RemoveExtraCharacters(string input) { string result = input.Trim(); result = result.Replace("\n", " "); result = result.Replace("\r", " "); result = result.Replace("\t", " "); result = result.Replace(" ", " "); result = result.Replace(" ", " "); result = result.Replace("<br>", " "); result = StringCompare.RemoveDuplicateSpace(result); return(result); }
public override bool CheckExpectation(IWebDriver webDriver) { IWebElement element = Utils.GetElementByPath.GetElement(Target, webDriver); var text = element.Text; var matches = StringCompare.IsMatch(text, MatchType, Text); if (!matches) { Message = $"`{Target.Path}` expected to be `{Text}` but was `{text}` (Match type: {MatchType})"; } return(matches); }
public void checkStringCompare() { wordsDictionary = StringCollect.dictionaryCollect("englishWordsDictionary.txt"); var ecryptedString = Ecrypt.EncryptStringLine(stringToCheck, ecryptKey); for (int key = 1; key < 27; key++) { string decryptedMessage = Ecrypt.DecryptStringLine(ecryptedString, key); decryptedMessage = decryptedMessage.ToLower(); if (StringCompare.CompareStrings(decryptedMessage, wordsDictionary)) { Assert.AreEqual(decryptedMessage, stringToCheck); } } }
/// <summary> /// Select a new page for the view. /// </summary> /// <param name="newPageName"> /// Name of the page to display. /// </param> private void NewPage(string newPageName) { if (StringCompare.SimpleCompare(newPageName, ReportsViewModel.CalendarSelector)) { this.CurrentWorkspace = this.calendarViewModel; } else if (StringCompare.SimpleCompare(newPageName, ReportsViewModel.EventSelector)) { this.CurrentWorkspace = this.eventReportViewModel; } this.ResetSelectedPage(newPageName); this.RaisePropertyChangedEvent(nameof(this.CurrentWorkspace)); }
/// <summary> /// Convert a string to a visibility /// </summary> /// <param name="value">value to convert</param> /// <param name="targetType">not used</param> /// <param name="parameter">not used</param> /// <param name="culture">not used</param> /// <returns>visibility value</returns> public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value == null || value.GetType() != typeof(string)) { return(this.NotVisibile()); } string check = (string)value; if (StringCompare.CompareEmpty(this.AssessmentString)) { return(StringCompare.CompareNullOrEmpty(check) ? this.NotVisibile() : Visibility.Visible); } return(StringCompare.SimpleCompare(check, AssessmentString) ? this.NotVisibile() : Visibility.Visible); }
private bool Equals(BsonValue value1, BsonValue value2) { if (value1.IsString && value2.IsString) { if (_stringComparisonIgnoreWhiteSpace) { return(StringCompare.EqualsIgnoreWhiteSpace(value1.AsString, value2.AsString, _stringComparisonIgnoreCase)); } if (_stringComparisonIgnoreCase) { return(string.Equals(value1.AsString, value2.AsString, StringComparison.InvariantCultureIgnoreCase)); } } return(value1 == value2); }
/// <summary> /// Sorting input string collection using as comparion input method. /// </summary> /// <param name="collection">Input string collection.</param> /// <param name="comparer">Comaprion method.</param> /// <returns></returns> public string[] Sort(string[] collection, StringCompare comparer) { for (int i = 0; i < collection.Length - 1; i++) { for (int j = i + 1; j < collection.Length; j++) { if (comparer(collection[i], collection[j]) == 1) { string temp = collection[i]; collection[i] = collection[j]; collection[j] = temp; } } } return(collection.ToArray()); }
public static bool CompareString(this string source, string compareTo, StringCompare compare, StringComparison comparison) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (compareTo == null) { throw new ArgumentNullException(nameof(compareTo)); } switch (compare) { case StringCompare.Equals: return(source.Equals(compareTo, comparison)); case StringCompare.NotEquals: return(!source.Equals(compareTo, comparison)); case StringCompare.Contains: return(source.IndexOf(compareTo, comparison) >= 0); case StringCompare.NotContains: return(source.IndexOf(compareTo, comparison) < 0); case StringCompare.RegexLike: return(Regex.IsMatch(source, compareTo)); case StringCompare.StartsWith: return(source.StartsWith(compareTo, comparison)); case StringCompare.NotStartsWith: return(!source.StartsWith(compareTo, comparison)); case StringCompare.EndsWith: return(source.EndsWith(compareTo, comparison)); case StringCompare.NotEndsWith: return(!source.EndsWith(compareTo, comparison)); default: throw new ArgumentOutOfRangeException(nameof(compare), compare, null); } }
public static string GetDealerExpModelsEnpointByBrandYear(string brand, string year, string dealerid) { string enpointString = string.Empty; if (StringCompare.stringEqualsIgnoreCase(brand, Brand.RZR)) { enpointString = string.Concat(UrlBuilder.getRzrLandingPageURL(), string.Format(DEALER_EXPERIENCE_ENDPOINT, year, dealerid)); } else if (StringCompare.stringEqualsIgnoreCase(brand, Brand.RAN)) { enpointString = string.Concat(UrlBuilder.getRangerLandingPageURL(), string.Format(DEALER_EXPERIENCE_ENDPOINT, year, dealerid)); } else if (StringCompare.stringEqualsIgnoreCase(brand, Brand.ATV)) { enpointString = string.Concat(UrlBuilder.getSportsmanLandingPageURL(), string.Format(DEALER_EXPERIENCE_ENDPOINT, year, dealerid)); } else if (StringCompare.stringEqualsIgnoreCase(brand, Brand.ACE)) { enpointString = string.Concat(UrlBuilder.getAceLandingPageURL(), string.Format(DEALER_EXPERIENCE_ENDPOINT, year, dealerid)); } else if (StringCompare.stringEqualsIgnoreCase(brand, Brand.GEN)) { enpointString = string.Concat(UrlBuilder.getGeneralLandingPageURL(), string.Format(DEALER_EXPERIENCE_ENDPOINT, year, dealerid)); } else if (StringCompare.stringEqualsIgnoreCase(brand, Brand.IND)) { enpointString = string.Concat(UrlBuilder.getIndianLandingPageURL(), string.Format(DEALER_EXPERIENCE_ENDPOINT, year, dealerid)); } else if (StringCompare.stringEqualsIgnoreCase(brand, Brand.SLG)) { enpointString = string.Concat(UrlBuilder.getSlgLandingPageURL(), string.Format(DEALER_EXPERIENCE_ENDPOINT, year, dealerid)); } else if (StringCompare.stringEqualsIgnoreCase(brand, Brand.SNO)) { enpointString = string.Concat(UrlBuilder.getSnoLandingPageURL(), string.Format(DEALER_EXPERIENCE_ENDPOINT, year, dealerid)); } else if (StringCompare.stringEqualsIgnoreCase(brand, Brand.GEM)) { enpointString = string.Concat(UrlBuilder.getGemLandingPageURL(), string.Format(DEALER_EXPERIENCE_ENDPOINT, year, dealerid)); } return(enpointString); }
public static int Main() { StringCompare test = new StringCompare(); TestLibrary.TestFramework.BeginTestCase("StringCompare"); if (test.RunTests()) { TestLibrary.TestFramework.EndTestCase(); TestLibrary.TestFramework.LogInformation("PASS"); return(100); } else { TestLibrary.TestFramework.EndTestCase(); TestLibrary.TestFramework.LogInformation("FAIL"); return(0); } }
static void Main(string[] args) { string[] str; string s; StringCompare compare1 = new StringCompare(CompareByLength); StringCompare compare2 = new StringCompare(CompareByAlphabet); Console.WriteLine("Введите строку:"); s = Console.ReadLine(); str = s.Split(' '); Sort(str, compare1, compare2); for (int i = 0; i < str.Length; i++) Console.Write("{0} ", str[i]); Console.WriteLine(); Console.Write("Нажмите любую клавишу для закрытия программы."); Console.ReadKey(); }
public static Expression <Func <TEntity, bool> > GetInstanceStringCompareExpression <TEntity>( string propertyName, string value, StringCompare compare, StringComparer comparer) { var type = typeof(TEntity); var parameter = Expression.Parameter(type, StringExpressionParameterName); var property = type.GetRuntimeProperty(propertyName); if (parameter == null) { throw new InvalidOperationException($"Property '{propertyName}' not found."); } var comparison = ExpressionHelper.GetInstanceStringCompareExpression <TEntity>( Expression.MakeMemberAccess(parameter, property), Expression.Constant(value), parameter, compare, comparer); return(comparison); }
public static TextRange FindCSSClassStyleUrlValuePosition(ref string pageHtml, int startindex) { int valueStart, valueEnd; const string strCSSUrlValue = "url("; TextRange result; // = new TextRange(-1, -1); result.End = -1; result.Start = -1; //============================== if (startindex >= pageHtml.Length) { return(result); } // Find first position valueStart = StringCompare.IndexOfIgnoreCase(ref pageHtml, strCSSUrlValue, startindex); if (valueStart == -1) { return(result); } valueStart += strCSSUrlValue.Length; valueEnd = StringCompare.IndexOfMatchCase(ref pageHtml, ")", valueStart); if (valueEnd == -1) { return(result); } if (valueEnd > StringCompare.IndexOfMatchCase(ref pageHtml, ";", valueStart)) { return(result); } result.Start = valueStart; result.End = valueEnd; return(result); }
public static string GetCompareString(StringCompare cm) { if (cm == AiGlobals.StringCompare.EqualTo) { return("EqualTo"); } if (cm == AiGlobals.StringCompare.Contains) { return("Contains"); } if (cm == AiGlobals.StringCompare.StartsWith) { return("StartsWith"); } if (cm == AiGlobals.StringCompare.DoesNotContain) { return("DoesNotContain"); } return(string.Empty); }
/// <summary> /// сортировка элементов массива /// </summary> static public void Sort(string[] str, StringCompare compare1, StringCompare compare2) { string temp; for (int i = 0; i < str.Length - 1; i++) { for (int j = i + 1; j < str.Length; j++) { if (compare1(str[i], str[j]) == 1) { temp = str[i]; str[i] = str[j]; str[j] = temp; } if ((compare1(str[i], str[j]) == 0) && (compare2(str[i], str[j]) == 1)) { temp = str[i]; str[i] = str[j]; str[j] = temp; } } } }
public static int Main() { StringCompare test = new StringCompare(); TestLibrary.TestFramework.BeginTestCase("StringCompare"); if (test.RunTests()) { TestLibrary.TestFramework.EndTestCase(); TestLibrary.TestFramework.LogInformation("PASS"); return 100; } else { TestLibrary.TestFramework.EndTestCase(); TestLibrary.TestFramework.LogInformation("FAIL"); return 0; } }
/// <summary> /// Is this value of the specified type /// </summary> /// <param name="Value">Value to compare</param> /// <param name="ComparisonType">Comparison type</param> /// <returns>True if it is of the type specified, false otherwise</returns> public static bool Is(this string Value, StringCompare ComparisonType) { if (ComparisonType == StringCompare.CreditCard) { long CheckSum = 0; Value = Value.Replace("-", "").Reverse(); for (int x = 0; x < Value.Length; ++x) { if (!Value[x].Is(CharIs.Digit)) return false; int TempValue = (Value[x] - '0') * (x % 2 == 1 ? 2 : 1); while (TempValue > 0) { CheckSum += TempValue % 10; TempValue /= 10; } } return (CheckSum % 10) == 0; } if (ComparisonType == StringCompare.Unicode) { return string.IsNullOrEmpty(Value) || Regex.Replace(Value, @"[^\u0000-\u007F]", "") != Value; } return Value.Is("", StringCompare.Anagram); }
/// <summary> /// Is this value of the specified type /// </summary> /// <param name="Value1">Value 1 to compare</param> /// <param name="Value2">Value 2 to compare</param> /// <param name="ComparisonType">Comparison type</param> /// <returns>True if it is of the type specified, false otherwise</returns> public static bool Is(this string Value1, string Value2, StringCompare ComparisonType) { if (ComparisonType != StringCompare.Anagram) return Value1.Is(ComparisonType); return new string(Value1.OrderBy(x => x).ToArray()) == new string(Value2.OrderBy(x => x).ToArray()); }