2using System.Collections.Generic;
11 private readonly
string value;
12 private readonly
string lowerCase;
21 this.lowerCase =
Value?.ToLower();
27 public string Value =>
this?.value;
37 return this.value ??
string.Empty;
46 return this.lowerCase?.GetHashCode() ?? 0;
58 public override bool Equals(
object obj)
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);
65 return this.lowerCase is
null;
85 return this.lowerCase?.CompareTo(other.lowerCase) ?? (other.lowerCase is
null ? 0 : -1);
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;
138 return S1?.lowerCase == S2?.lowerCase;
146 return S1?.lowerCase != S2?.lowerCase;
154 return string.Compare(S1?.lowerCase, S2?.lowerCase) < 0;
162 return string.Compare(S1?.lowerCase, S2?.lowerCase) > 0;
170 return string.Compare(S1?.lowerCase, S2?.lowerCase) <= 0;
178 return string.Compare(S1?.lowerCase, S2?.lowerCase) >= 0;
186 return S1?.lowerCase == S2?.ToLower();
194 return S1?.lowerCase != S2?.ToLower();
202 return string.Compare(S1?.lowerCase, S2?.ToLower()) < 0;
210 return string.Compare(S1?.lowerCase, S2?.ToLower()) > 0;
218 return string.Compare(S1?.lowerCase, S2?.ToLower()) <= 0;
226 return string.Compare(S1?.lowerCase, S2?.ToLower()) >= 0;
234 return string.Compare(S1, S2?.lowerCase,
true) == 0;
242 return string.Compare(S1, S2?.lowerCase,
true) != 0;
250 return string.Compare(S1, S2?.lowerCase,
true) < 0;
258 return string.Compare(S1, S2?.lowerCase,
true) > 0;
266 return string.Compare(S1, S2?.lowerCase,
true) <= 0;
274 return string.Compare(S1, S2?.lowerCase,
true) >= 0;
290 return S1?.value + S2;
298 return S1 + S2?.value;
312 : this(new string(value))
326 : this(new string(c, count))
346 : this(new string(value, startIndex, length))
361 public char this[
int index] => this.value[index];
386 return string.Compare(strA.lowerCase, strB.lowerCase);
417 return string.Compare(strA.lowerCase, indexA, strB.lowerCase, indexB, length, comparisonType);
453 return string.Compare(strA.lowerCase, indexA, strB.lowerCase, indexB, length);
484 return string.Compare(strA.lowerCase, strB.lowerCase, comparisonType);
520 return string.CompareOrdinal(strA.lowerCase, indexA, strB.lowerCase, indexB, length);
541 return string.CompareOrdinal(strA.lowerCase, strB.lowerCase);
694 return Concat<CaseInsensitiveString>(values);
760 return string.Equals(a?.lowerCase, b?.lowerCase, comparisonType);
778 return string.Equals(a?.lowerCase, b?.lowerCase);
1031 return string.IsNullOrEmpty(value?.value);
1047 return string.IsNullOrWhiteSpace(value?.value);
1198 return this.lowerCase.Contains(value.lowerCase);
1228 public void CopyTo(
int sourceIndex,
char[] destination,
int destinationIndex,
int count)
1230 this.value.CopyTo(sourceIndex, destination, destinationIndex, count);
1254 return this.lowerCase.EndsWith(value.lowerCase, comparisonType);
1271 return this.lowerCase.EndsWith(value.lowerCase);
1287 return this.lowerCase?.Equals(value?.lowerCase) ?? value is
null;
1310 return this.lowerCase?.Equals(value?.lowerCase, comparisonType) ?? value is
null;
1336 return this.lowerCase.IndexOf(value.lowerCase, comparisonType);
1373 return this.lowerCase.IndexOf(value.lowerCase, startIndex, count, comparisonType);
1403 return this.lowerCase.IndexOf(value.lowerCase, startIndex, count);
1428 return this.lowerCase.IndexOf(value.lowerCase, startIndex);
1447 return this.lowerCase.IndexOf(value.lowerCase);
1472 public int IndexOf(
char value,
int startIndex,
int count)
1474 return this.lowerCase.IndexOf(
char.ToLower(value), startIndex, count);
1496 return this.lowerCase.IndexOf(
char.ToLower(value), startIndex);
1528 return this.lowerCase.IndexOf(value.lowerCase, startIndex, comparisonType);
1544 return this.lowerCase.IndexOf(
char.ToLower(value));
1574 return this.lowerCase.IndexOfAny(ToLower(anyOf), startIndex, count);
1577 private static char[] ToLower(
char[] A)
1579 int i, c = A.Length;
1581 A = (
char[])A.Clone();
1583 for (i = 0; i < c; i++)
1584 A[i] =
char.ToLower(A[i]);
1613 return this.lowerCase.IndexOfAny(ToLower(anyOf), startIndex);
1632 return this.lowerCase.IndexOfAny(ToLower(anyOf));
1644 int Result =
int.MaxValue;
1645 int i, j, c = anyOf.
Length;
1648 for (i = 0; i < c; i++)
1650 j = this.lowerCase.IndexOf(anyOf[i].lowerCase, startIndex, count);
1651 if (j >= 0 && j < Result)
1655 count = j - startIndex;
1726 return this.lowerCase.LastIndexOf(
char.ToLower(value));
1751 return this.lowerCase.LastIndexOf(
char.ToLower(value), startIndex);
1782 return this.lowerCase.LastIndexOf(
char.ToLower(value), startIndex, count);
1802 return this.lowerCase.LastIndexOf(value.lowerCase);
1834 return this.lowerCase.LastIndexOf(value.lowerCase, startIndex);
1873 return this.lowerCase.LastIndexOf(value.lowerCase, startIndex, count);
1919 return this.lowerCase.LastIndexOf(value.lowerCase, startIndex, count, comparisonType);
1959 return this.lowerCase.LastIndexOf(value.lowerCase, startIndex, comparisonType);
1986 return this.lowerCase.LastIndexOf(value.lowerCase, comparisonType);
2005 return this.lowerCase.LastIndexOfAny(ToLower(anyOf));
2035 return this.lowerCase.LastIndexOfAny(ToLower(anyOf), startIndex);
2069 return this.lowerCase.LastIndexOfAny(ToLower(anyOf), startIndex, count);
2236 string s = this.value;
2237 string s2 = this.lowerCase;
2238 int i = s2.
IndexOf(oldValue.lowerCase);
2245 s = s.Remove(i + Diff, c);
2246 s = s.Insert(i + Diff, newValue?.value);
2248 i = s2.IndexOf(oldValue.lowerCase, i + c);
2272 string s = this.value.
Replace(oldChar, newChar);
2273 char ch =
char.ToLower(oldChar);
2276 s = s.Replace(ch,
char.ToLower(newChar));
2278 s = s.Replace(
char.ToUpper(oldChar),
char.ToUpper(newChar));
2298 return this.
Split(separator,
int.MaxValue, StringSplitOptions.None);
2323 return this.
Split(separator, count, StringSplitOptions.None);
2356 char[] A = ToLower(separator);
2357 int i = this.lowerCase.IndexOfAny(A);
2359 List<CaseInsensitiveString> Result =
new List<CaseInsensitiveString>();
2362 while (i >= 0 && count > 0)
2364 s = this.value.Substring(Last + 1, i - Last - 1);
2366 if (options != StringSplitOptions.RemoveEmptyEntries || !
string.IsNullOrEmpty(s))
2373 i = this.lowerCase.IndexOfAny(A, i + 1);
2378 s = this.value.Substring(Last + 1);
2380 if (options != StringSplitOptions.RemoveEmptyEntries || !
string.IsNullOrEmpty(s))
2384 return Result.ToArray();
2411 return this.
Split(separator,
int.MaxValue, options);
2445 List<CaseInsensitiveString> Result =
new List<CaseInsensitiveString>();
2448 while (i >= 0 && count > 0)
2450 s = this.value.Substring(Last + 1, i - Last - 1);
2452 if (options != StringSplitOptions.RemoveEmptyEntries || !
string.IsNullOrEmpty(s))
2464 s = this.value.Substring(Last + 1);
2466 if (options != StringSplitOptions.RemoveEmptyEntries || !
string.IsNullOrEmpty(s))
2470 return Result.ToArray();
2497 return this.
Split(separator,
int.MaxValue, options);
2515 return this.lowerCase.StartsWith(value.lowerCase);
2539 return this.lowerCase.StartsWith(value.lowerCase, comparisonType);
2606 return this.value.ToCharArray(startIndex, length);
2619 return this.value.ToCharArray();
2655 private static char[] UpperAndLowerCases(
char[] trimChars)
2657 List<char> A =
new List<char>();
2658 int i, c = trimChars.Length;
2661 for (i = 0; i < c; i++)
2666 ch2 =
char.ToLower(ch);
2670 ch2 =
char.ToUpper(ch);
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....
override string ToString()
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 .