Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
CaseInsensitiveString.cs
1using System;
2using System.Collections.Generic;
3
4namespace Waher.Persistence
5{
9 public class CaseInsensitiveString : IComparable<CaseInsensitiveString>, IComparable
10 {
11 private readonly string value;
12 private readonly string lowerCase;
13
19 {
20 this.value = Value;
21 this.lowerCase = Value?.ToLower();
22 }
23
27 public string Value => this?.value;
28
32 public string LowerCase => this?.lowerCase;
33
35 public override string ToString()
36 {
37 return this.value ?? string.Empty;
38 }
39
44 public override int GetHashCode()
45 {
46 return this.lowerCase?.GetHashCode() ?? 0;
47 }
48
58 public override bool Equals(object obj)
59 {
60 if (obj is CaseInsensitiveString S)
61 return this.lowerCase?.Equals(S?.lowerCase) ?? (S.lowerCase is null);
62 else if (obj is string S2)
63 return this.lowerCase?.Equals(S2?.ToLower()) ?? (S2 is null);
64 else if (obj is null)
65 return this.lowerCase is null;
66 else
67 return false;
68 }
69
84 {
85 return this.lowerCase?.CompareTo(other.lowerCase) ?? (other.lowerCase is null ? 0 : -1);
86 }
87
101 public int CompareTo(object obj)
102 {
103 if (obj is CaseInsensitiveString S)
104 return this.lowerCase?.CompareTo(S.lowerCase) ?? (S.lowerCase is null ? 0 : -1);
105 else if (obj is string S2)
106 return this.lowerCase?.CompareTo(S2?.ToLower()) ?? (S2 is null ? 0 : -1);
107 else if (obj is null)
108 return this.lowerCase is null ? 0 : 1;
109 else
110 return -1;
111 }
112
118 public static implicit operator string(CaseInsensitiveString S)
119 {
120 return S?.value;
121 }
122
128 public static implicit operator CaseInsensitiveString(string S)
129 {
130 return S is null ? null : new CaseInsensitiveString(S);
131 }
132
137 {
138 return S1?.lowerCase == S2?.lowerCase;
139 }
140
145 {
146 return S1?.lowerCase != S2?.lowerCase;
147 }
148
153 {
154 return string.Compare(S1?.lowerCase, S2?.lowerCase) < 0;
155 }
156
161 {
162 return string.Compare(S1?.lowerCase, S2?.lowerCase) > 0;
163 }
164
169 {
170 return string.Compare(S1?.lowerCase, S2?.lowerCase) <= 0;
171 }
172
177 {
178 return string.Compare(S1?.lowerCase, S2?.lowerCase) >= 0;
179 }
180
184 public static bool operator ==(CaseInsensitiveString S1, string S2)
185 {
186 return S1?.lowerCase == S2?.ToLower();
187 }
188
192 public static bool operator !=(CaseInsensitiveString S1, string S2)
193 {
194 return S1?.lowerCase != S2?.ToLower();
195 }
196
200 public static bool operator <(CaseInsensitiveString S1, string S2)
201 {
202 return string.Compare(S1?.lowerCase, S2?.ToLower()) < 0;
203 }
204
208 public static bool operator >(CaseInsensitiveString S1, string S2)
209 {
210 return string.Compare(S1?.lowerCase, S2?.ToLower()) > 0;
211 }
212
216 public static bool operator <=(CaseInsensitiveString S1, string S2)
217 {
218 return string.Compare(S1?.lowerCase, S2?.ToLower()) <= 0;
219 }
220
224 public static bool operator >=(CaseInsensitiveString S1, string S2)
225 {
226 return string.Compare(S1?.lowerCase, S2?.ToLower()) >= 0;
227 }
228
232 public static bool operator ==(string S1, CaseInsensitiveString S2)
233 {
234 return string.Compare(S1, S2?.lowerCase, true) == 0;
235 }
236
240 public static bool operator !=(string S1, CaseInsensitiveString S2)
241 {
242 return string.Compare(S1, S2?.lowerCase, true) != 0;
243 }
244
248 public static bool operator <(string S1, CaseInsensitiveString S2)
249 {
250 return string.Compare(S1, S2?.lowerCase, true) < 0;
251 }
252
256 public static bool operator >(string S1, CaseInsensitiveString S2)
257 {
258 return string.Compare(S1, S2?.lowerCase, true) > 0;
259 }
260
264 public static bool operator <=(string S1, CaseInsensitiveString S2)
265 {
266 return string.Compare(S1, S2?.lowerCase, true) <= 0;
267 }
268
272 public static bool operator >=(string S1, CaseInsensitiveString S2)
273 {
274 return string.Compare(S1, S2?.lowerCase, true) >= 0;
275 }
276
281 {
282 return (CaseInsensitiveString)(S1?.value + S2?.value);
283 }
284
288 public static string operator +(CaseInsensitiveString S1, string S2)
289 {
290 return S1?.value + S2;
291 }
292
296 public static string operator +(string S1, CaseInsensitiveString S2)
297 {
298 return S1 + S2?.value;
299 }
300
304 public static readonly CaseInsensitiveString Empty = new CaseInsensitiveString(string.Empty);
305
311 public CaseInsensitiveString(char[] value)
312 : this(new string(value))
313 {
314 }
315
325 public CaseInsensitiveString(char c, int count)
326 : this(new string(c, count))
327 {
328 }
329
345 public CaseInsensitiveString(char[] value, int startIndex, int length)
346 : this(new string(value, startIndex, length))
347 {
348 }
349
361 public char this[int index] => this.value[index];
362
369 public int Length => this.value.Length;
370
371 //
385 {
386 return string.Compare(strA.lowerCase, strB.lowerCase);
387 }
388
415 public static int Compare(CaseInsensitiveString strA, int indexA, CaseInsensitiveString strB, int indexB, int length, StringComparison comparisonType)
416 {
417 return string.Compare(strA.lowerCase, indexA, strB.lowerCase, indexB, length, comparisonType);
418 }
419
451 public static int Compare(CaseInsensitiveString strA, int indexA, CaseInsensitiveString strB, int indexB, int length)
452 {
453 return string.Compare(strA.lowerCase, indexA, strB.lowerCase, indexB, length);
454 }
455
456 //
482 public static int Compare(CaseInsensitiveString strA, CaseInsensitiveString strB, StringComparison comparisonType)
483 {
484 return string.Compare(strA.lowerCase, strB.lowerCase, comparisonType);
485 }
486
487 //
518 public static int CompareOrdinal(CaseInsensitiveString strA, int indexA, CaseInsensitiveString strB, int indexB, int length)
519 {
520 return string.CompareOrdinal(strA.lowerCase, indexA, strB.lowerCase, indexB, length);
521 }
522
523 //
540 {
541 return string.CompareOrdinal(strA.lowerCase, strB.lowerCase);
542 }
543
544 //
561 public static CaseInsensitiveString Concat<T>(IEnumerable<T> values)
562 {
563 return (CaseInsensitiveString)string.Concat<T>(values);
564 }
565
582 {
583 return (CaseInsensitiveString)string.Concat<CaseInsensitiveString>(values);
584 }
585
599 {
600 return (CaseInsensitiveString)string.Concat(str0?.value, str1?.value);
601 }
602
622 {
623 return (CaseInsensitiveString)string.Concat(str0?.value, str1?.value, str2?.value, str3?.value);
624 }
625
641 public static CaseInsensitiveString Concat(object arg0, object arg1, object arg2)
642 {
643 return (CaseInsensitiveString)string.Concat(arg0, arg1, arg2);
644 }
645
658 public static CaseInsensitiveString Concat(object arg0, object arg1)
659 {
660 return (CaseInsensitiveString)string.Concat(arg0, arg1);
661 }
662
673 public static CaseInsensitiveString Concat(object arg0)
674 {
675 return (CaseInsensitiveString)string.Concat(arg0);
676 }
677
692 public static CaseInsensitiveString Concat(IEnumerable<CaseInsensitiveString> values)
693 {
694 return Concat<CaseInsensitiveString>(values);
695 }
696
713 public static CaseInsensitiveString Concat(params object[] args)
714 {
715 return (CaseInsensitiveString)string.Concat(args);
716 }
717
734 {
735 return (CaseInsensitiveString)string.Concat(str0?.value, str1?.value, str2?.value);
736 }
737
758 public static bool Equals(CaseInsensitiveString a, CaseInsensitiveString b, StringComparison comparisonType)
759 {
760 return string.Equals(a?.lowerCase, b?.lowerCase, comparisonType);
761 }
762
777 {
778 return string.Equals(a?.lowerCase, b?.lowerCase);
779 }
780
801 public static CaseInsensitiveString Format(CaseInsensitiveString format, object arg0)
802 {
803 return (CaseInsensitiveString)string.Format(format.lowerCase, arg0);
804 }
805
831 public static CaseInsensitiveString Format(IFormatProvider provider, CaseInsensitiveString format, params object[] args)
832 {
833 return (CaseInsensitiveString)string.Format(provider, format.lowerCase, args);
834 }
835
867 public static CaseInsensitiveString Format(IFormatProvider provider, CaseInsensitiveString format, object arg0, object arg1, object arg2)
868 {
869 return (CaseInsensitiveString)string.Format(provider, format.lowerCase, arg0, arg1, arg2);
870 }
871
895 public static CaseInsensitiveString Format(CaseInsensitiveString format, object arg0, object arg1)
896 {
897 return (CaseInsensitiveString)string.Format(format.lowerCase, arg0, arg1);
898 }
899
927 public static CaseInsensitiveString Format(IFormatProvider provider, CaseInsensitiveString format, object arg0, object arg1)
928 {
929 return (CaseInsensitiveString)string.Format(provider, format.lowerCase, arg0, arg1);
930 }
931
957 public static CaseInsensitiveString Format(IFormatProvider provider, CaseInsensitiveString format, object arg0)
958 {
959 return (CaseInsensitiveString)string.Format(provider, format.lowerCase, arg0);
960 }
961
983 public static CaseInsensitiveString Format(CaseInsensitiveString format, params object[] args)
984 {
985 return (CaseInsensitiveString)string.Format(format.lowerCase, args);
986 }
987
1015 public static CaseInsensitiveString Format(CaseInsensitiveString format, object arg0, object arg1, object arg2)
1016 {
1017 return (CaseInsensitiveString)string.Format(format.lowerCase, arg0, arg1, arg2);
1018 }
1019
1029 public static bool IsNullOrEmpty(CaseInsensitiveString value)
1030 {
1031 return string.IsNullOrEmpty(value?.value);
1032 }
1033
1046 {
1047 return string.IsNullOrWhiteSpace(value?.value);
1048 }
1049
1068 public static CaseInsensitiveString Join(CaseInsensitiveString separator, params object[] values)
1069 {
1070 return (CaseInsensitiveString)string.Join(separator?.value, values);
1071 }
1072
1092 {
1093 return (CaseInsensitiveString)string.Join(separator?.value, value.ToStringArray());
1094 }
1095
1117 public static CaseInsensitiveString Join<T>(CaseInsensitiveString separator, IEnumerable<T> values)
1118 {
1119 return (CaseInsensitiveString)string.Join(separator?.value, values);
1120 }
1121
1154 public static CaseInsensitiveString Join(CaseInsensitiveString separator, CaseInsensitiveString[] value, int startIndex, int count)
1155 {
1156 return (CaseInsensitiveString)string.Join(separator?.value, value.ToStringArray(), startIndex, count);
1157 }
1158
1178 public static CaseInsensitiveString Join(CaseInsensitiveString separator, IEnumerable<CaseInsensitiveString> values)
1179 {
1180 return (CaseInsensitiveString)string.Join(separator?.value, values);
1181 }
1182
1197 {
1198 return this.lowerCase.Contains(value.lowerCase);
1199 }
1200
1228 public void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count)
1229 {
1230 this.value.CopyTo(sourceIndex, destination, destinationIndex, count);
1231 }
1232
1252 public bool EndsWith(CaseInsensitiveString value, StringComparison comparisonType)
1253 {
1254 return this.lowerCase.EndsWith(value.lowerCase, comparisonType);
1255 }
1256
1270 {
1271 return this.lowerCase.EndsWith(value.lowerCase);
1272 }
1273
1286 {
1287 return this.lowerCase?.Equals(value?.lowerCase) ?? value is null;
1288 }
1289
1308 public bool Equals(CaseInsensitiveString value, StringComparison comparisonType)
1309 {
1310 return this.lowerCase?.Equals(value?.lowerCase, comparisonType) ?? value is null;
1311 }
1312
1334 public int IndexOf(CaseInsensitiveString value, StringComparison comparisonType)
1335 {
1336 return this.lowerCase.IndexOf(value.lowerCase, comparisonType);
1337 }
1338
1371 public int IndexOf(CaseInsensitiveString value, int startIndex, int count, StringComparison comparisonType)
1372 {
1373 return this.lowerCase.IndexOf(value.lowerCase, startIndex, count, comparisonType);
1374 }
1375
1401 public int IndexOf(CaseInsensitiveString value, int startIndex, int count)
1402 {
1403 return this.lowerCase.IndexOf(value.lowerCase, startIndex, count);
1404 }
1405
1426 public int IndexOf(CaseInsensitiveString value, int startIndex)
1427 {
1428 return this.lowerCase.IndexOf(value.lowerCase, startIndex);
1429 }
1430
1446 {
1447 return this.lowerCase.IndexOf(value.lowerCase);
1448 }
1449
1472 public int IndexOf(char value, int startIndex, int count)
1473 {
1474 return this.lowerCase.IndexOf(char.ToLower(value), startIndex, count);
1475 }
1476
1494 public int IndexOf(char value, int startIndex)
1495 {
1496 return this.lowerCase.IndexOf(char.ToLower(value), startIndex);
1497 }
1498
1526 public int IndexOf(CaseInsensitiveString value, int startIndex, StringComparison comparisonType)
1527 {
1528 return this.lowerCase.IndexOf(value.lowerCase, startIndex, comparisonType);
1529 }
1530
1542 public int IndexOf(char value)
1543 {
1544 return this.lowerCase.IndexOf(char.ToLower(value));
1545 }
1546
1572 public int IndexOfAny(char[] anyOf, int startIndex, int count)
1573 {
1574 return this.lowerCase.IndexOfAny(ToLower(anyOf), startIndex, count);
1575 }
1576
1577 private static char[] ToLower(char[] A)
1578 {
1579 int i, c = A.Length;
1580
1581 A = (char[])A.Clone();
1582
1583 for (i = 0; i < c; i++)
1584 A[i] = char.ToLower(A[i]);
1585
1586 return A;
1587 }
1588
1611 public int IndexOfAny(char[] anyOf, int startIndex)
1612 {
1613 return this.lowerCase.IndexOfAny(ToLower(anyOf), startIndex);
1614 }
1615
1630 public int IndexOfAny(char[] anyOf)
1631 {
1632 return this.lowerCase.IndexOfAny(ToLower(anyOf));
1633 }
1634
1642 public int IndexOfAny(CaseInsensitiveString[] anyOf, int startIndex, int count)
1643 {
1644 int Result = int.MaxValue;
1645 int i, j, c = anyOf.Length;
1646 bool Found = false;
1647
1648 for (i = 0; i < c; i++)
1649 {
1650 j = this.lowerCase.IndexOf(anyOf[i].lowerCase, startIndex, count);
1651 if (j >= 0 && j < Result)
1652 {
1653 Result = j;
1654 Found = true;
1655 count = j - startIndex;
1656 if (count == 0)
1657 break;
1658 }
1659 }
1660
1661 if (Found)
1662 return Result;
1663 else
1664 return -1;
1665 }
1666
1673 public int IndexOfAny(CaseInsensitiveString[] anyOf, int startIndex)
1674 {
1675 return this.IndexOfAny(anyOf, startIndex, this.value.Length - startIndex);
1676 }
1677
1684 {
1685 return this.IndexOfAny(anyOf, 0, this.value.Length);
1686 }
1687
1709 {
1710 return (CaseInsensitiveString)this.value.Insert(startIndex, value?.value);
1711 }
1712
1724 public int LastIndexOf(char value)
1725 {
1726 return this.lowerCase.LastIndexOf(char.ToLower(value));
1727 }
1728
1749 public int LastIndexOf(char value, int startIndex)
1750 {
1751 return this.lowerCase.LastIndexOf(char.ToLower(value), startIndex);
1752 }
1753
1780 public int LastIndexOf(char value, int startIndex, int count)
1781 {
1782 return this.lowerCase.LastIndexOf(char.ToLower(value), startIndex, count);
1783 }
1784
1801 {
1802 return this.lowerCase.LastIndexOf(value.lowerCase);
1803 }
1804
1832 public int LastIndexOf(CaseInsensitiveString value, int startIndex)
1833 {
1834 return this.lowerCase.LastIndexOf(value.lowerCase, startIndex);
1835 }
1836
1871 public int LastIndexOf(CaseInsensitiveString value, int startIndex, int count)
1872 {
1873 return this.lowerCase.LastIndexOf(value.lowerCase, startIndex, count);
1874 }
1875
1917 public int LastIndexOf(CaseInsensitiveString value, int startIndex, int count, StringComparison comparisonType)
1918 {
1919 return this.lowerCase.LastIndexOf(value.lowerCase, startIndex, count, comparisonType);
1920 }
1921
1957 public int LastIndexOf(CaseInsensitiveString value, int startIndex, StringComparison comparisonType)
1958 {
1959 return this.lowerCase.LastIndexOf(value.lowerCase, startIndex, comparisonType);
1960 }
1961
1984 public int LastIndexOf(CaseInsensitiveString value, StringComparison comparisonType)
1985 {
1986 return this.lowerCase.LastIndexOf(value.lowerCase, comparisonType);
1987 }
1988
2003 public int LastIndexOfAny(char[] anyOf)
2004 {
2005 return this.lowerCase.LastIndexOfAny(ToLower(anyOf));
2006 }
2007
2033 public int LastIndexOfAny(char[] anyOf, int startIndex)
2034 {
2035 return this.lowerCase.LastIndexOfAny(ToLower(anyOf), startIndex);
2036 }
2037
2067 public int LastIndexOfAny(char[] anyOf, int startIndex, int count)
2068 {
2069 return this.lowerCase.LastIndexOfAny(ToLower(anyOf), startIndex, count);
2070 }
2071
2090 public CaseInsensitiveString PadLeft(int totalWidth)
2091 {
2092 return (CaseInsensitiveString)this.value.PadLeft(totalWidth);
2093 }
2094
2117 public CaseInsensitiveString PadLeft(int totalWidth, char paddingChar)
2118 {
2119 return (CaseInsensitiveString)this.value.PadLeft(totalWidth, paddingChar);
2120 }
2121
2140 public CaseInsensitiveString PadRight(int totalWidth)
2141 {
2142 return (CaseInsensitiveString)this.value.PadRight(totalWidth);
2143 }
2144
2167 public CaseInsensitiveString PadRight(int totalWidth, char paddingChar)
2168 {
2169 return (CaseInsensitiveString)this.value.PadRight(totalWidth, paddingChar);
2170 }
2171
2186 public CaseInsensitiveString Remove(int startIndex)
2187 {
2188 return (CaseInsensitiveString)this.value.Remove(startIndex);
2189 }
2190
2208 public CaseInsensitiveString Remove(int startIndex, int count)
2209 {
2210 return (CaseInsensitiveString)this.value.Remove(startIndex, count);
2211 }
2212
2235 {
2236 string s = this.value;
2237 string s2 = this.lowerCase;
2238 int i = s2.IndexOf(oldValue.lowerCase);
2239 int c = oldValue.Length;
2240 int d = newValue.Length;
2241 int Diff = 0;
2242
2243 while (i >= 0)
2244 {
2245 s = s.Remove(i + Diff, c);
2246 s = s.Insert(i + Diff, newValue?.value);
2247
2248 i = s2.IndexOf(oldValue.lowerCase, i + c);
2249 Diff += d - c;
2250 }
2251
2252 return (CaseInsensitiveString)s;
2253 }
2254
2270 public CaseInsensitiveString Replace(char oldChar, char newChar)
2271 {
2272 string s = this.value.Replace(oldChar, newChar);
2273 char ch = char.ToLower(oldChar);
2274
2275 if (ch != oldChar)
2276 s = s.Replace(ch, char.ToLower(newChar));
2277 else
2278 s = s.Replace(char.ToUpper(oldChar), char.ToUpper(newChar));
2279
2280 return (CaseInsensitiveString)s;
2281 }
2282
2296 public CaseInsensitiveString[] Split(params char[] separator)
2297 {
2298 return this.Split(separator, int.MaxValue, StringSplitOptions.None);
2299 }
2300
2321 public CaseInsensitiveString[] Split(char[] separator, int count)
2322 {
2323 return this.Split(separator, count, StringSplitOptions.None);
2324 }
2325
2354 public CaseInsensitiveString[] Split(char[] separator, int count, StringSplitOptions options)
2355 {
2356 char[] A = ToLower(separator);
2357 int i = this.lowerCase.IndexOfAny(A);
2358 int Last = -1;
2359 List<CaseInsensitiveString> Result = new List<CaseInsensitiveString>();
2360 string s;
2361
2362 while (i >= 0 && count > 0)
2363 {
2364 s = this.value.Substring(Last + 1, i - Last - 1);
2365
2366 if (options != StringSplitOptions.RemoveEmptyEntries || !string.IsNullOrEmpty(s))
2367 {
2368 count--;
2369 Result.Add((CaseInsensitiveString)s);
2370 }
2371
2372 Last = i;
2373 i = this.lowerCase.IndexOfAny(A, i + 1);
2374 }
2375
2376 if (count > 0)
2377 {
2378 s = this.value.Substring(Last + 1);
2379
2380 if (options != StringSplitOptions.RemoveEmptyEntries || !string.IsNullOrEmpty(s))
2381 Result.Add((CaseInsensitiveString)this.value.Substring(Last + 1));
2382 }
2383
2384 return Result.ToArray();
2385 }
2386
2409 public CaseInsensitiveString[] Split(char[] separator, StringSplitOptions options)
2410 {
2411 return this.Split(separator, int.MaxValue, options);
2412 }
2413
2441 public CaseInsensitiveString[] Split(CaseInsensitiveString[] separator, int count, StringSplitOptions options)
2442 {
2443 int i = this.IndexOfAny(separator);
2444 int Last = -1;
2445 List<CaseInsensitiveString> Result = new List<CaseInsensitiveString>();
2446 string s;
2447
2448 while (i >= 0 && count > 0)
2449 {
2450 s = this.value.Substring(Last + 1, i - Last - 1);
2451
2452 if (options != StringSplitOptions.RemoveEmptyEntries || !string.IsNullOrEmpty(s))
2453 {
2454 count--;
2455 Result.Add((CaseInsensitiveString)s);
2456 }
2457
2458 Last = i;
2459 i = this.IndexOfAny(separator, i + 1);
2460 }
2461
2462 if (count > 0)
2463 {
2464 s = this.value.Substring(Last + 1);
2465
2466 if (options != StringSplitOptions.RemoveEmptyEntries || !string.IsNullOrEmpty(s))
2467 Result.Add((CaseInsensitiveString)this.value.Substring(Last + 1));
2468 }
2469
2470 return Result.ToArray();
2471
2472 }
2473
2495 public CaseInsensitiveString[] Split(CaseInsensitiveString[] separator, StringSplitOptions options)
2496 {
2497 return this.Split(separator, int.MaxValue, options);
2498 }
2499
2514 {
2515 return this.lowerCase.StartsWith(value.lowerCase);
2516 }
2517
2537 public bool StartsWith(CaseInsensitiveString value, StringComparison comparisonType)
2538 {
2539 return this.lowerCase.StartsWith(value.lowerCase, comparisonType);
2540 }
2541
2561 public CaseInsensitiveString Substring(int startIndex, int length)
2562 {
2563 return (CaseInsensitiveString)this.value.Substring(startIndex, length);
2564 }
2565
2581 public CaseInsensitiveString Substring(int startIndex)
2582 {
2583 return (CaseInsensitiveString)this.value.Substring(startIndex);
2584 }
2585
2604 public char[] ToCharArray(int startIndex, int length)
2605 {
2606 return this.value.ToCharArray(startIndex, length);
2607 }
2608
2617 public char[] ToCharArray()
2618 {
2619 return this.value.ToCharArray();
2620 }
2621
2632 {
2633 return (CaseInsensitiveString)this.value.Trim();
2634 }
2635
2650 public CaseInsensitiveString Trim(params char[] trimChars)
2651 {
2652 return (CaseInsensitiveString)this.value.Trim(UpperAndLowerCases(trimChars));
2653 }
2654
2655 private static char[] UpperAndLowerCases(char[] trimChars)
2656 {
2657 List<char> A = new List<char>();
2658 int i, c = trimChars.Length;
2659 char ch, ch2;
2660
2661 for (i = 0; i < c; i++)
2662 {
2663 ch = trimChars[i];
2664 A.Add(ch);
2665
2666 ch2 = char.ToLower(ch);
2667 if (ch2 != ch)
2668 A.Add(ch2);
2669
2670 ch2 = char.ToUpper(ch);
2671 if (ch2 != ch)
2672 A.Add(ch2);
2673 }
2674
2675 return A.ToArray();
2676 }
2677
2692 public CaseInsensitiveString TrimEnd(params char[] trimChars)
2693 {
2694 return (CaseInsensitiveString)this.value.TrimEnd(UpperAndLowerCases(trimChars));
2695 }
2696
2709 public CaseInsensitiveString TrimStart(params char[] trimChars)
2710 {
2711 return (CaseInsensitiveString)this.value.TrimStart(UpperAndLowerCases(trimChars));
2712 }
2713
2714 }
2715}
Represents a case-insensitive string.
bool StartsWith(CaseInsensitiveString value, StringComparison comparisonType)
Determines whether the beginning of this string instance matches the specified string when compared u...
int IndexOf(char value, int startIndex)
Reports the zero-based index of the first occurrence of the specified Unicode character in this strin...
int LastIndexOf(CaseInsensitiveString value, int startIndex, StringComparison comparisonType)
Reports the zero-based index of the last occurrence of a specified string within the current System....
string Value
String-representation of the case-insensitive string. (Representation is case sensitive....
static bool operator==(CaseInsensitiveString S1, CaseInsensitiveString S2)
Equality operator
static bool operator<(CaseInsensitiveString S1, CaseInsensitiveString S2)
Lesser-than operator
static CaseInsensitiveString Concat< T >(IEnumerable< T > values)
Concatenates the members of an System.Collections.Generic.IEnumerable`1 implementation.
bool Equals(CaseInsensitiveString value, StringComparison comparisonType)
Determines whether this string and a specified System.CaseInsensitiveString object have the same valu...
CaseInsensitiveString Trim(params char[] trimChars)
Removes all leading and trailing occurrences of a set of characters specified in an array from the cu...
static readonly CaseInsensitiveString Empty
Empty case-insensitive string
int LastIndexOf(CaseInsensitiveString value)
Reports the zero-based index position of the last occurrence of a specified string within this instan...
bool Contains(CaseInsensitiveString value)
Returns a value indicating whether a specified substring occurs within this string.
CaseInsensitiveString TrimStart(params char[] trimChars)
Removes all leading occurrences of a set of characters specified in an array from the current System....
int IndexOfAny(CaseInsensitiveString[] anyOf)
Checks for the first occurrence of the case-insensitive strings in anyOf .
static CaseInsensitiveString Join(CaseInsensitiveString separator, CaseInsensitiveString[] value, int startIndex, int count)
Concatenates the specified elements of a string array, using the specified separator between each ele...
static CaseInsensitiveString Format(IFormatProvider provider, CaseInsensitiveString format, object arg0)
Replaces the format item or items in a specified string with the string representation of the corresp...
int LastIndexOfAny(char[] anyOf, int startIndex)
Reports the zero-based index position of the last occurrence in this instance of one or more characte...
CaseInsensitiveString PadRight(int totalWidth)
Returns a new string that left-aligns the characters in this string by padding them with spaces on th...
int Length
Gets the number of characters in the current CaseInsensitiveString object.
CaseInsensitiveString[] Split(CaseInsensitiveString[] separator, int count, StringSplitOptions options)
Returns a string array that contains the substrings in this string that are delimited by elements of ...
static CaseInsensitiveString Format(CaseInsensitiveString format, object arg0)
Replaces one or more format items in a specified string with the string representation of a specified...
static CaseInsensitiveString Concat(object arg0)
Creates the string representation of a specified object.
string LowerCase
Lower-case representation of the case-insensitive string.
CaseInsensitiveString PadLeft(int totalWidth, char paddingChar)
Returns a new string that right-aligns the characters in this instance by padding them on the left wi...
bool Equals(CaseInsensitiveString value)
Determines whether this instance and another specified System.CaseInsensitiveString object have the s...
CaseInsensitiveString(string Value)
Represents a case-insensitive string.
int IndexOf(CaseInsensitiveString value, StringComparison comparisonType)
Reports the zero-based index of the first occurrence of the specified string in the current System....
CaseInsensitiveString PadRight(int totalWidth, char paddingChar)
Returns a new string that left-aligns the characters in this string by padding them on the right with...
int IndexOf(char value, int startIndex, int count)
Reports the zero-based index of the first occurrence of the specified character in this instance....
CaseInsensitiveString PadLeft(int totalWidth)
Returns a new string that right-aligns the characters in this instance by padding them with spaces on...
int LastIndexOf(char value)
Reports the zero-based index position of the last occurrence of a specified Unicode character within ...
static bool operator>=(CaseInsensitiveString S1, CaseInsensitiveString S2)
Greater-than-or-equal-to operator
static bool IsNullOrEmpty(CaseInsensitiveString value)
Indicates whether the specified string is null or an CaseInsensitiveString.Empty string.
static CaseInsensitiveString Format(CaseInsensitiveString format, params object[] args)
Replaces the format item in a specified string with the string representation of a corresponding obje...
int IndexOfAny(char[] anyOf)
Reports the zero-based index of the first occurrence in this instance of any character in a specified...
static bool Equals(CaseInsensitiveString a, CaseInsensitiveString b, StringComparison comparisonType)
Determines whether two specified System.CaseInsensitiveString objects have the same value....
static CaseInsensitiveString operator+(CaseInsensitiveString S1, CaseInsensitiveString S2)
Addition operator
static int Compare(CaseInsensitiveString strA, int indexA, CaseInsensitiveString strB, int indexB, int length, StringComparison comparisonType)
Compares substrings of two specified CaseInsensitiveString objects using the specified rules,...
int LastIndexOf(char value, int startIndex)
Reports the zero-based index position of the last occurrence of a specified Unicode character within ...
CaseInsensitiveString Replace(char oldChar, char newChar)
Returns a new string in which all occurrences of a specified Unicode character in this instance are r...
int IndexOf(CaseInsensitiveString value)
Reports the zero-based index of the first occurrence of the specified string in this instance.
CaseInsensitiveString TrimEnd(params char[] trimChars)
Removes all trailing occurrences of a set of characters specified in an array from the current System...
CaseInsensitiveString[] Split(char[] separator, int count)
Returns a string array that contains the substrings in this instance that are delimited by elements o...
static CaseInsensitiveString Format(IFormatProvider provider, CaseInsensitiveString format, params object[] args)
Replaces the format items in a specified string with the string representations of corresponding obje...
int LastIndexOfAny(char[] anyOf, int startIndex, int count)
Reports the zero-based index position of the last occurrence in this instance of one or more characte...
static CaseInsensitiveString Concat(CaseInsensitiveString str0, CaseInsensitiveString str1, CaseInsensitiveString str2)
Concatenates three specified instances of CaseInsensitiveString.
static CaseInsensitiveString Join(CaseInsensitiveString separator, IEnumerable< CaseInsensitiveString > values)
Concatenates the members of a constructed System.Collections.Generic.IEnumerable`1 collection of type...
int IndexOf(char value)
Reports the zero-based index of the first occurrence of the specified Unicode character in this strin...
CaseInsensitiveString[] Split(char[] separator, StringSplitOptions options)
Returns a string array that contains the substrings in this string that are delimited by elements of ...
CaseInsensitiveString Trim()
Removes all leading and trailing white-space characters from the current CaseInsensitiveString object...
static int Compare(CaseInsensitiveString strA, CaseInsensitiveString strB, StringComparison comparisonType)
Compares two specified CaseInsensitiveString objects using the specified rules, and returns an intege...
int CompareTo(CaseInsensitiveString other)
Compares this instance with a specified System.CaseInsensitiveString object and indicates whether thi...
CaseInsensitiveString(char[] value)
Initializes a new instance of the CaseInsensitiveString class to the value indicated by an array of U...
void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count)
Copies a specified number of characters from a specified position in this instance to a specified pos...
CaseInsensitiveString Replace(CaseInsensitiveString oldValue, CaseInsensitiveString newValue)
Returns a new string in which all occurrences of a specified string in the current instance are repla...
CaseInsensitiveString Remove(int startIndex)
Returns a new string in which all the characters in the current instance, beginning at a specified po...
static int CompareOrdinal(CaseInsensitiveString strA, int indexA, CaseInsensitiveString strB, int indexB, int length)
Compares substrings of two specified CaseInsensitiveString objects by evaluating the numeric values o...
static CaseInsensitiveString Join(CaseInsensitiveString separator, params CaseInsensitiveString[] value)
Concatenates all the elements of a string array, using the specified separator between each element.
int LastIndexOf(CaseInsensitiveString value, int startIndex, int count, StringComparison comparisonType)
Reports the zero-based index position of the last occurrence of a specified string within this instan...
static bool operator<=(CaseInsensitiveString S1, CaseInsensitiveString S2)
Lesser-than-or-equal-to operator
CaseInsensitiveString(char[] value, int startIndex, int length)
Initializes a new instance of the CaseInsensitiveString class to the value indicated by an array of U...
CaseInsensitiveString[] Split(CaseInsensitiveString[] separator, StringSplitOptions options)
Returns a string array that contains the substrings in this string that are delimited by elements of ...
int LastIndexOfAny(char[] anyOf)
Reports the zero-based index position of the last occurrence in this instance of one or more characte...
static CaseInsensitiveString Format(IFormatProvider provider, CaseInsensitiveString format, object arg0, object arg1, object arg2)
Replaces the format items in a specified string with the string representation of three specified obj...
bool StartsWith(CaseInsensitiveString value)
Determines whether the beginning of this string instance matches the specified string.
static bool IsNullOrWhiteSpace(CaseInsensitiveString value)
Indicates whether a specified string is null, empty, or consists only of white-space characters.
static CaseInsensitiveString Join(CaseInsensitiveString separator, params object[] values)
Concatenates the elements of an object array, using the specified separator between each element.
CaseInsensitiveString[] Split(params char[] separator)
Returns a string array that contains the substrings in this instance that are delimited by elements o...
static CaseInsensitiveString Concat(object arg0, object arg1)
Concatenates the string representations of two specified objects.
CaseInsensitiveString Insert(int startIndex, CaseInsensitiveString value)
Returns a new string in which a specified string is inserted at a specified index position in this in...
override int GetHashCode()
Returns the hash code for this string.
static int Compare(CaseInsensitiveString strA, CaseInsensitiveString strB)
Compares two specified CaseInsensitiveString objects and returns an integer that indicates their rela...
static bool operator>(CaseInsensitiveString S1, CaseInsensitiveString S2)
Greater-than operator
char[] ToCharArray()
Copies the characters in this instance to a Unicode character array.
static CaseInsensitiveString Format(CaseInsensitiveString format, object arg0, object arg1)
Replaces the format items in a specified string with the string representation of two specified objec...
int IndexOf(CaseInsensitiveString value, int startIndex)
Reports the zero-based index of the first occurrence of the specified string in this instance....
int LastIndexOf(char value, int startIndex, int count)
Reports the zero-based index position of the last occurrence of the specified Unicode character in a ...
static CaseInsensitiveString Concat(CaseInsensitiveString str0, CaseInsensitiveString str1)
Concatenates two specified instances of CaseInsensitiveString.
CaseInsensitiveString Substring(int startIndex)
Retrieves a substring from this instance. The substring starts at a specified character position and ...
int LastIndexOf(CaseInsensitiveString value, int startIndex, int count)
Reports the zero-based index position of the last occurrence of a specified string within this instan...
int IndexOf(CaseInsensitiveString value, int startIndex, StringComparison comparisonType)
Reports the zero-based index of the first occurrence of the specified string in the current System....
int IndexOf(CaseInsensitiveString value, int startIndex, int count)
Reports the zero-based index of the first occurrence of the specified string in this instance....
static CaseInsensitiveString Concat(params object[] args)
Concatenates the string representations of the elements in a specified System.Object array.
int LastIndexOf(CaseInsensitiveString value, int startIndex)
Reports the zero-based index position of the last occurrence of a specified string within this instan...
int LastIndexOf(CaseInsensitiveString value, StringComparison comparisonType)
Reports the zero-based index of the last occurrence of a specified string within the current System....
static CaseInsensitiveString Format(CaseInsensitiveString format, object arg0, object arg1, object arg2)
Replaces the format items in a specified string with the string representation of three specified obj...
CaseInsensitiveString(char c, int count)
Initializes a new instance of the CaseInsensitiveString class to the value indicated by a specified U...
static int CompareOrdinal(CaseInsensitiveString strA, CaseInsensitiveString strB)
Compares two specified CaseInsensitiveString objects by evaluating the numeric values of the correspo...
static CaseInsensitiveString Concat(object arg0, object arg1, object arg2)
Concatenates the string representations of three specified objects.
int CompareTo(object obj)
Compares this instance with a specified System.CaseInsensitiveString object and indicates whether thi...
static CaseInsensitiveString Join< T >(CaseInsensitiveString separator, IEnumerable< T > values)
Concatenates the members of a collection, using the specified separator between each member.
CaseInsensitiveString Substring(int startIndex, int length)
Retrieves a substring from this instance. The substring starts at a specified character position and ...
int IndexOfAny(char[] anyOf, int startIndex)
Reports the zero-based index of the first occurrence in this instance of any character in a specified...
CaseInsensitiveString Remove(int startIndex, int count)
Returns a new string in which a specified number of characters in the current instance beginning at a...
int IndexOfAny(char[] anyOf, int startIndex, int count)
Reports the zero-based index of the first occurrence in this instance of any character in a specified...
static bool operator!=(CaseInsensitiveString S1, CaseInsensitiveString S2)
Non-Equality operator
override bool Equals(object obj)
Determines whether this instance and a specified object, which must also be a System....
static CaseInsensitiveString Format(IFormatProvider provider, CaseInsensitiveString format, object arg0, object arg1)
Replaces the format items in a specified string with the string representation of two specified objec...
int IndexOf(CaseInsensitiveString value, int startIndex, int count, StringComparison comparisonType)
Reports the zero-based index of the first occurrence of the specified string in the current System....
static CaseInsensitiveString Concat(IEnumerable< CaseInsensitiveString > values)
Concatenates the members of a constructed System.Collections.Generic.IEnumerable`1 collection of type...
bool EndsWith(CaseInsensitiveString value)
Determines whether the end of this string instance matches the specified string.
CaseInsensitiveString[] Split(char[] separator, int count, StringSplitOptions options)
Returns a string array that contains the substrings in this string that are delimited by elements of ...
static int Compare(CaseInsensitiveString strA, int indexA, CaseInsensitiveString strB, int indexB, int length)
Compares substrings of two specified CaseInsensitiveString objects and returns an integer that indica...
static CaseInsensitiveString Concat(CaseInsensitiveString str0, CaseInsensitiveString str1, CaseInsensitiveString str2, CaseInsensitiveString str3)
Concatenates four specified instances of CaseInsensitiveString.
char[] ToCharArray(int startIndex, int length)
Copies the characters in a specified substring in this instance to a Unicode character array.
static CaseInsensitiveString Concat(params CaseInsensitiveString[] values)
Concatenates the elements of a specified CaseInsensitiveString array.
int IndexOfAny(CaseInsensitiveString[] anyOf, int startIndex)
Checks for the first occurrence of the case-insensitive strings in anyOf .
bool EndsWith(CaseInsensitiveString value, StringComparison comparisonType)
Determines whether the end of this string instance matches the specified string when compared using t...
static bool Equals(CaseInsensitiveString a, CaseInsensitiveString b)
Determines whether two specified System.CaseInsensitiveString objects have the same value.
int IndexOfAny(CaseInsensitiveString[] anyOf, int startIndex, int count)
Checks for the first occurrence of the case-insensitive strings in anyOf .