Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string title = "ASTRINGTOTEST";
- title.Contains("string");
- culture.CompareInfo.IndexOf(paragraph, word, CompareOptions.IgnoreCase) >= 0
- string title = "STRING";
- bool contains = title.IndexOf("string", StringComparison.OrdinalIgnoreCase) >= 0;
- public static class StringExtensions
- {
- public static bool Contains(this string source, string toCheck, StringComparison comp)
- {
- return source.IndexOf(toCheck, comp) >= 0;
- }
- }
- ...
- string title = "STRING";
- bool contains = title.Contains("string", StringComparison.OrdinalIgnoreCase);
- string title = "STRING";
- if (title.IndexOf("string", 0, StringComparison.CurrentCultureIgnoreCase) != -1)
- {
- // The string exists in the original
- }
- bool contains = Regex.IsMatch("StRiNG to search", "string", RegexOptions.IgnoreCase);
- public static bool Contains(this string source, string toCheck, StringComparison comp)
- {
- if (string.IsNullOrEmpty(toCheck) || string.IsNullOrEmpty(source))
- return true;
- return source.IndexOf(toCheck, comp) >= 0;
- }
- string title = "string":
- title.ToUpper().Contains("STRING") // returns true
- public static class StringExtensions
- {
- /// <summary>
- /// Allows case insensitive checks
- /// </summary>
- public static bool Contains(this string source, string toCheck, StringComparison comp)
- {
- return source.IndexOf(toCheck, comp) >= 0;
- }
- }
- Regex.IsMatch(file,fileNamestr,RegexOptions.IgnoreCase)
- string title = "STRING";
- if (title.IndexOf("string", 0, StringComparison.[YourDecision]) != -1)
- {
- // The string exists in the original
- }
- string s="AbcdEf";
- if(s.ToLower().Contains("def"))
- {
- Console.WriteLine("yes");
- }
- Dim str As String = "UPPERlower"
- Dim b As Boolean = InStr(str, "UpperLower")
- string myString = "Hello World";
- bool contains = Microsoft.VisualBasic.Strings.InStr(myString, "world");
- private static int InternalInStrText(int lStartPos, string sSrc, string sFind)
- {
- int num = sSrc == null ? 0 : sSrc.Length;
- if (lStartPos > num || num == 0)
- return -1;
- if (sFind == null || sFind.Length == 0)
- return lStartPos;
- else
- return Utils.GetCultureInfo().CompareInfo.IndexOf(sSrc, sFind, lStartPos, CompareOptions.IgnoreCase | CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth);
- }
- string.Compare("string", "STRING", new System.Globalization.CultureInfo("en-US"), System.Globalization.CompareOptions.IgnoreCase);
- /// <summary>
- /// Determines whether the source contains the sequence.
- /// </summary>
- /// <typeparam name="T">The type of the items in the sequences.</typeparam>
- /// <param name="sourceEnumerator">The source enumerator.</param>
- /// <param name="sequenceEnumerator">The sequence enumerator.</param>
- /// <param name="equalityComparer">An equality comparer.</param>
- /// <remarks>
- /// An empty sequence will return <c>true</c>.
- /// The sequence must support <see cref="IEnumerator.Reset"/>
- /// if it does not begin the source.
- /// </remarks>
- /// <returns>
- /// <c>true</c> if the source contains the sequence;
- /// otherwise <c>false</c>.
- /// </returns>
- public static bool Contains<T>(
- IEnumerator<T> sourceEnumerator,
- IEnumerator<T> sequenceEnumerator,
- IEqualityComparer<T> equalityComparer)
- {
- if (equalityComparer == null)
- {
- equalityComparer = EqualityComparer<T>.Default;
- }
- while (sequenceEnumerator.MoveNext())
- {
- if (sourceEnumerator.MoveNext())
- {
- if (!equalityComparer.Equals(
- sourceEnumerator.Current,
- sequenceEnumerator.Current))
- {
- sequenceEnumerator.Reset();
- }
- }
- else
- {
- return false;
- }
- }
- return true;
- }
- public static bool Contains<T>(
- this IEnumerable<T> source,
- IEnumerable<T> sequence,
- IEqualityComparer<T> equalityComparer = null)
- {
- if (sequence == null)
- {
- throw new ArgumentNullException("sequence");
- }
- using(var sequenceEnumerator = sequence.GetEnumerator())
- using(var sourceEnumerator = source.GetEnumerator())
- {
- return Contains(
- sourceEnumerator,
- sequenceEnumerator,
- equalityComparer);
- }
- }
- // The optional parameter ensures the generic overload is invoked
- // not the string.Contains() implementation.
- "testable".Contains("est", EqualityComparer<char>.Default)
- using System.Globalization;
- public static bool Contains(
- this string source,
- string value,
- CultureInfo culture = null,
- CompareOptions options = CompareOptions.None)
- {
- if (value == null)
- {
- throw new ArgumentNullException("value");
- }
- var compareInfo = culture == null ?
- CultureInfo.CurrentCulture.CompareInfo :
- culture.CompareInfo;
- var sourceEnumerator = StringInfo.GetTextElementEnumerator(source);
- var sequenceEnumerator = StringInfo.GetTextElementEnumerator(value);
- while (sequenceEnumerator.MoveNext())
- {
- if (sourceEnumerator.MoveNext())
- {
- if (!(compareInfo.Compare(
- sourceEnumerator.Current,
- sequenceEnumerator.Current,
- options) == 0))
- {
- sequenceEnumerator.Reset();
- }
- }
- else
- {
- return false;
- }
- }
- return true;
- }
- "testable".Contains("EST", StringComparer.CurrentCultureIgnoreCase)
- Regex.IsMatch(title, "string", RegexOptions.IgnoreCase);
- public static class StringExtensions
- {
- public static bool Contains(this string source, string toCheck, bool bCaseInsensitive )
- {
- return source.IndexOf(toCheck, bCaseInsensitive ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) >= 0;
- }
- }
- if( "main String substring".Contains("SUBSTRING", true) )
- ....
- var s="Factory Reset";
- var txt="reset";
- int first = s.IndexOf(txt, StringComparison.InvariantCultureIgnoreCase) + txt.Length;
- var subString = s.Substring(first - txt.Length, txt.Length);
- if ("strcmpstring1".IndexOf(Convert.ToString("strcmpstring2"), StringComparison.CurrentCultureIgnoreCase) >= 0){return true;}else{return false;}
- public static class StringExtension
- {
- #region Public Methods
- public static bool ExContains(this string fullText, string value)
- {
- return ExIndexOf(fullText, value) > -1;
- }
- public static bool ExEquals(this string text, string textToCompare)
- {
- return text.Equals(textToCompare, StringComparison.OrdinalIgnoreCase);
- }
- public static bool ExHasAllEquals(this string text, params string[] textArgs)
- {
- for (int index = 0; index < textArgs.Length; index++)
- if (ExEquals(text, textArgs[index]) == false) return false;
- return true;
- }
- public static bool ExHasEquals(this string text, params string[] textArgs)
- {
- for (int index = 0; index < textArgs.Length; index++)
- if (ExEquals(text, textArgs[index])) return true;
- return false;
- }
- public static bool ExHasNoEquals(this string text, params string[] textArgs)
- {
- return ExHasEquals(text, textArgs) == false;
- }
- public static bool ExHasNotAllEquals(this string text, params string[] textArgs)
- {
- for (int index = 0; index < textArgs.Length; index++)
- if (ExEquals(text, textArgs[index])) return false;
- return true;
- }
- /// <summary>
- /// Reports the zero-based index of the first occurrence of the specified string
- /// in the current System.String object using StringComparison.InvariantCultureIgnoreCase.
- /// A parameter specifies the type of search to use for the specified string.
- /// </summary>
- /// <param name="fullText">
- /// The string to search inside.
- /// </param>
- /// <param name="value">
- /// The string to seek.
- /// </param>
- /// <returns>
- /// The index position of the value parameter if that string is found, or -1 if it
- /// is not. If value is System.String.Empty, the return value is 0.
- /// </returns>
- /// <exception cref="ArgumentNullException">
- /// fullText or value is null.
- /// </exception>
- public static int ExIndexOf(this string fullText, string value)
- {
- return fullText.IndexOf(value, StringComparison.OrdinalIgnoreCase);
- }
- public static bool ExNotEquals(this string text, string textToCompare)
- {
- return ExEquals(text, textToCompare) == false;
- }
- #endregion Public Methods
- }
- title.Contains("string") || title.Contains("string".ToUpper());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement