Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.45 KB | None | 0 0
  1. string title = "ASTRINGTOTEST";
  2. title.Contains("string");
  3.  
  4. culture.CompareInfo.IndexOf(paragraph, word, CompareOptions.IgnoreCase) >= 0
  5.  
  6. string title = "STRING";
  7. bool contains = title.IndexOf("string", StringComparison.OrdinalIgnoreCase) >= 0;
  8.  
  9. public static class StringExtensions
  10. {
  11. public static bool Contains(this string source, string toCheck, StringComparison comp)
  12. {
  13. return source.IndexOf(toCheck, comp) >= 0;
  14. }
  15. }
  16.  
  17. ...
  18.  
  19. string title = "STRING";
  20. bool contains = title.Contains("string", StringComparison.OrdinalIgnoreCase);
  21.  
  22. string title = "STRING";
  23.  
  24. if (title.IndexOf("string", 0, StringComparison.CurrentCultureIgnoreCase) != -1)
  25. {
  26. // The string exists in the original
  27. }
  28.  
  29. bool contains = Regex.IsMatch("StRiNG to search", "string", RegexOptions.IgnoreCase);
  30.  
  31. public static bool Contains(this string source, string toCheck, StringComparison comp)
  32. {
  33. if (string.IsNullOrEmpty(toCheck) || string.IsNullOrEmpty(source))
  34. return true;
  35.  
  36. return source.IndexOf(toCheck, comp) >= 0;
  37. }
  38.  
  39. string title = "string":
  40. title.ToUpper().Contains("STRING") // returns true
  41.  
  42. public static class StringExtensions
  43. {
  44. /// <summary>
  45. /// Allows case insensitive checks
  46. /// </summary>
  47. public static bool Contains(this string source, string toCheck, StringComparison comp)
  48. {
  49. return source.IndexOf(toCheck, comp) >= 0;
  50. }
  51. }
  52.  
  53. Regex.IsMatch(file,fileNamestr,RegexOptions.IgnoreCase)
  54.  
  55. string title = "STRING";
  56. if (title.IndexOf("string", 0, StringComparison.[YourDecision]) != -1)
  57. {
  58. // The string exists in the original
  59. }
  60.  
  61. string s="AbcdEf";
  62. if(s.ToLower().Contains("def"))
  63. {
  64. Console.WriteLine("yes");
  65. }
  66.  
  67. Dim str As String = "UPPERlower"
  68. Dim b As Boolean = InStr(str, "UpperLower")
  69.  
  70. string myString = "Hello World";
  71. bool contains = Microsoft.VisualBasic.Strings.InStr(myString, "world");
  72.  
  73. private static int InternalInStrText(int lStartPos, string sSrc, string sFind)
  74. {
  75. int num = sSrc == null ? 0 : sSrc.Length;
  76. if (lStartPos > num || num == 0)
  77. return -1;
  78. if (sFind == null || sFind.Length == 0)
  79. return lStartPos;
  80. else
  81. return Utils.GetCultureInfo().CompareInfo.IndexOf(sSrc, sFind, lStartPos, CompareOptions.IgnoreCase | CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth);
  82. }
  83.  
  84. string.Compare("string", "STRING", new System.Globalization.CultureInfo("en-US"), System.Globalization.CompareOptions.IgnoreCase);
  85.  
  86. /// <summary>
  87. /// Determines whether the source contains the sequence.
  88. /// </summary>
  89. /// <typeparam name="T">The type of the items in the sequences.</typeparam>
  90. /// <param name="sourceEnumerator">The source enumerator.</param>
  91. /// <param name="sequenceEnumerator">The sequence enumerator.</param>
  92. /// <param name="equalityComparer">An equality comparer.</param>
  93. /// <remarks>
  94. /// An empty sequence will return <c>true</c>.
  95. /// The sequence must support <see cref="IEnumerator.Reset"/>
  96. /// if it does not begin the source.
  97. /// </remarks>
  98. /// <returns>
  99. /// <c>true</c> if the source contains the sequence;
  100. /// otherwise <c>false</c>.
  101. /// </returns>
  102. public static bool Contains<T>(
  103. IEnumerator<T> sourceEnumerator,
  104. IEnumerator<T> sequenceEnumerator,
  105. IEqualityComparer<T> equalityComparer)
  106. {
  107. if (equalityComparer == null)
  108. {
  109. equalityComparer = EqualityComparer<T>.Default;
  110. }
  111.  
  112. while (sequenceEnumerator.MoveNext())
  113. {
  114. if (sourceEnumerator.MoveNext())
  115. {
  116. if (!equalityComparer.Equals(
  117. sourceEnumerator.Current,
  118. sequenceEnumerator.Current))
  119. {
  120. sequenceEnumerator.Reset();
  121. }
  122. }
  123. else
  124. {
  125. return false;
  126. }
  127. }
  128.  
  129. return true;
  130. }
  131.  
  132. public static bool Contains<T>(
  133. this IEnumerable<T> source,
  134. IEnumerable<T> sequence,
  135. IEqualityComparer<T> equalityComparer = null)
  136. {
  137. if (sequence == null)
  138. {
  139. throw new ArgumentNullException("sequence");
  140. }
  141.  
  142. using(var sequenceEnumerator = sequence.GetEnumerator())
  143. using(var sourceEnumerator = source.GetEnumerator())
  144. {
  145. return Contains(
  146. sourceEnumerator,
  147. sequenceEnumerator,
  148. equalityComparer);
  149. }
  150. }
  151.  
  152. // The optional parameter ensures the generic overload is invoked
  153. // not the string.Contains() implementation.
  154. "testable".Contains("est", EqualityComparer<char>.Default)
  155.  
  156. using System.Globalization;
  157.  
  158. public static bool Contains(
  159. this string source,
  160. string value,
  161. CultureInfo culture = null,
  162. CompareOptions options = CompareOptions.None)
  163. {
  164. if (value == null)
  165. {
  166. throw new ArgumentNullException("value");
  167. }
  168.  
  169. var compareInfo = culture == null ?
  170. CultureInfo.CurrentCulture.CompareInfo :
  171. culture.CompareInfo;
  172.  
  173. var sourceEnumerator = StringInfo.GetTextElementEnumerator(source);
  174. var sequenceEnumerator = StringInfo.GetTextElementEnumerator(value);
  175.  
  176. while (sequenceEnumerator.MoveNext())
  177. {
  178. if (sourceEnumerator.MoveNext())
  179. {
  180. if (!(compareInfo.Compare(
  181. sourceEnumerator.Current,
  182. sequenceEnumerator.Current,
  183. options) == 0))
  184. {
  185. sequenceEnumerator.Reset();
  186. }
  187. }
  188. else
  189. {
  190. return false;
  191. }
  192. }
  193.  
  194. return true;
  195. }
  196.  
  197. "testable".Contains("EST", StringComparer.CurrentCultureIgnoreCase)
  198.  
  199. Regex.IsMatch(title, "string", RegexOptions.IgnoreCase);
  200.  
  201. public static class StringExtensions
  202. {
  203. public static bool Contains(this string source, string toCheck, bool bCaseInsensitive )
  204. {
  205. return source.IndexOf(toCheck, bCaseInsensitive ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) >= 0;
  206. }
  207. }
  208.  
  209. if( "main String substring".Contains("SUBSTRING", true) )
  210. ....
  211.  
  212. var s="Factory Reset";
  213. var txt="reset";
  214. int first = s.IndexOf(txt, StringComparison.InvariantCultureIgnoreCase) + txt.Length;
  215. var subString = s.Substring(first - txt.Length, txt.Length);
  216.  
  217. if ("strcmpstring1".IndexOf(Convert.ToString("strcmpstring2"), StringComparison.CurrentCultureIgnoreCase) >= 0){return true;}else{return false;}
  218.  
  219. public static class StringExtension
  220. {
  221. #region Public Methods
  222.  
  223. public static bool ExContains(this string fullText, string value)
  224. {
  225. return ExIndexOf(fullText, value) > -1;
  226. }
  227.  
  228. public static bool ExEquals(this string text, string textToCompare)
  229. {
  230. return text.Equals(textToCompare, StringComparison.OrdinalIgnoreCase);
  231. }
  232.  
  233. public static bool ExHasAllEquals(this string text, params string[] textArgs)
  234. {
  235. for (int index = 0; index < textArgs.Length; index++)
  236. if (ExEquals(text, textArgs[index]) == false) return false;
  237. return true;
  238. }
  239.  
  240. public static bool ExHasEquals(this string text, params string[] textArgs)
  241. {
  242. for (int index = 0; index < textArgs.Length; index++)
  243. if (ExEquals(text, textArgs[index])) return true;
  244. return false;
  245. }
  246.  
  247. public static bool ExHasNoEquals(this string text, params string[] textArgs)
  248. {
  249. return ExHasEquals(text, textArgs) == false;
  250. }
  251.  
  252. public static bool ExHasNotAllEquals(this string text, params string[] textArgs)
  253. {
  254. for (int index = 0; index < textArgs.Length; index++)
  255. if (ExEquals(text, textArgs[index])) return false;
  256. return true;
  257. }
  258.  
  259. /// <summary>
  260. /// Reports the zero-based index of the first occurrence of the specified string
  261. /// in the current System.String object using StringComparison.InvariantCultureIgnoreCase.
  262. /// A parameter specifies the type of search to use for the specified string.
  263. /// </summary>
  264. /// <param name="fullText">
  265. /// The string to search inside.
  266. /// </param>
  267. /// <param name="value">
  268. /// The string to seek.
  269. /// </param>
  270. /// <returns>
  271. /// The index position of the value parameter if that string is found, or -1 if it
  272. /// is not. If value is System.String.Empty, the return value is 0.
  273. /// </returns>
  274. /// <exception cref="ArgumentNullException">
  275. /// fullText or value is null.
  276. /// </exception>
  277. public static int ExIndexOf(this string fullText, string value)
  278. {
  279. return fullText.IndexOf(value, StringComparison.OrdinalIgnoreCase);
  280. }
  281.  
  282. public static bool ExNotEquals(this string text, string textToCompare)
  283. {
  284. return ExEquals(text, textToCompare) == false;
  285. }
  286.  
  287. #endregion Public Methods
  288. }
  289.  
  290. title.Contains("string") || title.Contains("string".ToUpper());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement