mscorlib(4.0.0.0) API with additions
String.cs
1 using Microsoft.Win32;
2 using System.Collections;
8 using System.Security;
9 using System.Text;
10 using System.Threading;
11 
12 namespace System
13 {
15  [Serializable]
16  [ComVisible(true)]
17  [__DynamicallyInvokable]
18  public sealed class String : IComparable, ICloneable, IConvertible, IEnumerable, IComparable<string>, IEnumerable<char>, IEquatable<string>
19  {
20  [NonSerialized]
21  private int m_stringLength;
22 
23  [NonSerialized]
24  private char m_firstChar;
25 
26  private const int TrimHead = 0;
27 
28  private const int TrimTail = 1;
29 
30  private const int TrimBoth = 2;
31 
33  [__DynamicallyInvokable]
34  public static readonly string Empty;
35 
36  private const int charPtrAlignConst = 3;
37 
38  private const int alignConst = 7;
39 
40  internal char FirstChar => m_firstChar;
41 
47  [IndexerName("Chars")]
48  [__DynamicallyInvokable]
49  public char this[int index]
50  {
51  [MethodImpl(MethodImplOptions.InternalCall)]
52  [SecuritySafeCritical]
53  [__DynamicallyInvokable]
54  get;
55  }
56 
59  [__DynamicallyInvokable]
60  public int Length
61  {
62  [MethodImpl(MethodImplOptions.InternalCall)]
63  [SecuritySafeCritical]
64  [__DynamicallyInvokable]
65  get;
66  }
67 
74  [__DynamicallyInvokable]
75  public static string Join(string separator, params string[] value)
76  {
77  if (value == null)
78  {
79  throw new ArgumentNullException("value");
80  }
81  return Join(separator, value, 0, value.Length);
82  }
83 
90  [ComVisible(false)]
91  [__DynamicallyInvokable]
92  public static string Join(string separator, params object[] values)
93  {
94  if (values == null)
95  {
96  throw new ArgumentNullException("values");
97  }
98  if (values.Length == 0 || values[0] == null)
99  {
100  return Empty;
101  }
102  if (separator == null)
103  {
104  separator = Empty;
105  }
106  StringBuilder stringBuilder = StringBuilderCache.Acquire();
107  string text = values[0].ToString();
108  if (text != null)
109  {
110  stringBuilder.Append(text);
111  }
112  for (int i = 1; i < values.Length; i++)
113  {
114  stringBuilder.Append(separator);
115  if (values[i] != null)
116  {
117  text = values[i].ToString();
118  if (text != null)
119  {
120  stringBuilder.Append(text);
121  }
122  }
123  }
124  return StringBuilderCache.GetStringAndRelease(stringBuilder);
125  }
126 
134  [ComVisible(false)]
135  [__DynamicallyInvokable]
136  public static string Join<T>(string separator, IEnumerable<T> values)
137  {
138  if (values == null)
139  {
140  throw new ArgumentNullException("values");
141  }
142  if (separator == null)
143  {
144  separator = Empty;
145  }
146  using (IEnumerator<T> enumerator = values.GetEnumerator())
147  {
148  if (!enumerator.MoveNext())
149  {
150  return Empty;
151  }
152  StringBuilder stringBuilder = StringBuilderCache.Acquire();
153  if (enumerator.Current != null)
154  {
155  string text = enumerator.Current.ToString();
156  if (text != null)
157  {
158  stringBuilder.Append(text);
159  }
160  }
161  while (enumerator.MoveNext())
162  {
163  stringBuilder.Append(separator);
164  if (enumerator.Current != null)
165  {
166  string text2 = enumerator.Current.ToString();
167  if (text2 != null)
168  {
169  stringBuilder.Append(text2);
170  }
171  }
172  }
173  return StringBuilderCache.GetStringAndRelease(stringBuilder);
174  }
175  }
176 
183  [ComVisible(false)]
184  [__DynamicallyInvokable]
185  public static string Join(string separator, IEnumerable<string> values)
186  {
187  if (values == null)
188  {
189  throw new ArgumentNullException("values");
190  }
191  if (separator == null)
192  {
193  separator = Empty;
194  }
195  using (IEnumerator<string> enumerator = values.GetEnumerator())
196  {
197  if (!enumerator.MoveNext())
198  {
199  return Empty;
200  }
201  StringBuilder stringBuilder = StringBuilderCache.Acquire();
202  if (enumerator.Current != null)
203  {
204  stringBuilder.Append(enumerator.Current);
205  }
206  while (enumerator.MoveNext())
207  {
208  stringBuilder.Append(separator);
209  if (enumerator.Current != null)
210  {
211  stringBuilder.Append(enumerator.Current);
212  }
213  }
214  return StringBuilderCache.GetStringAndRelease(stringBuilder);
215  }
216  }
217 
231  [SecuritySafeCritical]
232  [__DynamicallyInvokable]
233  public unsafe static string Join(string separator, string[] value, int startIndex, int count)
234  {
235  if (value == null)
236  {
237  throw new ArgumentNullException("value");
238  }
239  if (startIndex < 0)
240  {
241  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndex"));
242  }
243  if (count < 0)
244  {
245  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NegativeCount"));
246  }
247  if (startIndex > value.Length - count)
248  {
249  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
250  }
251  if (separator == null)
252  {
253  separator = Empty;
254  }
255  if (count == 0)
256  {
257  return Empty;
258  }
259  int num = 0;
260  int num2 = startIndex + count - 1;
261  for (int i = startIndex; i <= num2; i++)
262  {
263  if (value[i] != null)
264  {
265  num += value[i].Length;
266  }
267  }
268  num += (count - 1) * separator.Length;
269  if (num < 0 || num + 1 < 0)
270  {
271  throw new OutOfMemoryException();
272  }
273  if (num == 0)
274  {
275  return Empty;
276  }
277  string text = FastAllocateString(num);
278  fixed (char* buffer = &text.m_firstChar)
279  {
280  UnSafeCharBuffer unSafeCharBuffer = new UnSafeCharBuffer(buffer, num);
281  unSafeCharBuffer.AppendString(value[startIndex]);
282  for (int j = startIndex + 1; j <= num2; j++)
283  {
284  unSafeCharBuffer.AppendString(separator);
285  unSafeCharBuffer.AppendString(value[j]);
286  }
287  }
288  return text;
289  }
290 
291  [SecuritySafeCritical]
292  private unsafe static int CompareOrdinalIgnoreCaseHelper(string strA, string strB)
293  {
294  int num = Math.Min(strA.Length, strB.Length);
295  fixed (char* ptr = &strA.m_firstChar)
296  {
297  fixed (char* ptr3 = &strB.m_firstChar)
298  {
299  char* ptr2 = ptr;
300  char* ptr4 = ptr3;
301  while (num != 0)
302  {
303  int num2 = *ptr2;
304  int num3 = *ptr4;
305  if ((uint)(num2 - 97) <= 25u)
306  {
307  num2 -= 32;
308  }
309  if ((uint)(num3 - 97) <= 25u)
310  {
311  num3 -= 32;
312  }
313  if (num2 != num3)
314  {
315  return num2 - num3;
316  }
317  ptr2++;
318  ptr4++;
319  num--;
320  }
321  return strA.Length - strB.Length;
322  }
323  }
324  }
325 
326  [MethodImpl(MethodImplOptions.InternalCall)]
327  [SecurityCritical]
328  internal static extern int nativeCompareOrdinalEx(string strA, int indexA, string strB, int indexB, int count);
329 
330  [MethodImpl(MethodImplOptions.InternalCall)]
331  [SecurityCritical]
332  internal unsafe static extern int nativeCompareOrdinalIgnoreCaseWC(string strA, sbyte* strBBytes);
333 
334  [SecuritySafeCritical]
335  internal unsafe static string SmallCharToUpper(string strIn)
336  {
337  int length = strIn.Length;
338  string text = FastAllocateString(length);
339  fixed (char* ptr = &strIn.m_firstChar)
340  {
341  fixed (char* ptr2 = &text.m_firstChar)
342  {
343  for (int i = 0; i < length; i++)
344  {
345  int num = ptr[i];
346  if ((uint)(num - 97) <= 25u)
347  {
348  num -= 32;
349  }
350  ptr2[i] = (char)num;
351  }
352  }
353  }
354  return text;
355  }
356 
357  [SecuritySafeCritical]
358  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
359  private unsafe static bool EqualsHelper(string strA, string strB)
360  {
361  int num = strA.Length;
362  fixed (char* ptr = &strA.m_firstChar)
363  {
364  fixed (char* ptr3 = &strB.m_firstChar)
365  {
366  char* ptr2 = ptr;
367  char* ptr4 = ptr3;
368  while (num >= 12)
369  {
370  if (*(long*)ptr2 != *(long*)ptr4)
371  {
372  return false;
373  }
374  if (*(long*)(ptr2 + 4) != *(long*)(ptr4 + 4))
375  {
376  return false;
377  }
378  if (*(long*)(ptr2 + 8) != *(long*)(ptr4 + 8))
379  {
380  return false;
381  }
382  ptr2 += 12;
383  ptr4 += 12;
384  num -= 12;
385  }
386  while (num > 0 && *(int*)ptr2 == *(int*)ptr4)
387  {
388  ptr2 += 2;
389  ptr4 += 2;
390  num -= 2;
391  }
392  return num <= 0;
393  }
394  }
395  }
396 
397  [SecuritySafeCritical]
398  private unsafe static int CompareOrdinalHelper(string strA, string strB)
399  {
400  int num = Math.Min(strA.Length, strB.Length);
401  int num2 = -1;
402  fixed (char* ptr = &strA.m_firstChar)
403  {
404  fixed (char* ptr3 = &strB.m_firstChar)
405  {
406  char* ptr2 = ptr;
407  char* ptr4 = ptr3;
408  while (num >= 10)
409  {
410  if (*(int*)ptr2 != *(int*)ptr4)
411  {
412  num2 = 0;
413  break;
414  }
415  if (*(int*)(ptr2 + 2) != *(int*)(ptr4 + 2))
416  {
417  num2 = 2;
418  break;
419  }
420  if (*(int*)(ptr2 + 4) != *(int*)(ptr4 + 4))
421  {
422  num2 = 4;
423  break;
424  }
425  if (*(int*)(ptr2 + 6) != *(int*)(ptr4 + 6))
426  {
427  num2 = 6;
428  break;
429  }
430  if (*(int*)(ptr2 + 8) != *(int*)(ptr4 + 8))
431  {
432  num2 = 8;
433  break;
434  }
435  ptr2 += 10;
436  ptr4 += 10;
437  num -= 10;
438  }
439  if (num2 != -1)
440  {
441  ptr2 += num2;
442  ptr4 += num2;
443  int result;
444  if ((result = *ptr2 - *ptr4) != 0)
445  {
446  return result;
447  }
448  return ptr2[1] - ptr4[1];
449  }
450  while (num > 0 && *(int*)ptr2 == *(int*)ptr4)
451  {
452  ptr2 += 2;
453  ptr4 += 2;
454  num -= 2;
455  }
456  if (num > 0)
457  {
458  int result2;
459  if ((result2 = *ptr2 - *ptr4) != 0)
460  {
461  return result2;
462  }
463  return ptr2[1] - ptr4[1];
464  }
465  return strA.Length - strB.Length;
466  }
467  }
468  }
469 
474  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
475  [__DynamicallyInvokable]
476  public override bool Equals(object obj)
477  {
478  if (this == null)
479  {
480  throw new NullReferenceException();
481  }
482  string text = obj as string;
483  if (text == null)
484  {
485  return false;
486  }
487  if (this == obj)
488  {
489  return true;
490  }
491  if (Length != text.Length)
492  {
493  return false;
494  }
495  return EqualsHelper(this, text);
496  }
497 
502  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
503  [__DynamicallyInvokable]
504  public bool Equals(string value)
505  {
506  if (this == null)
507  {
508  throw new NullReferenceException();
509  }
510  if (value == null)
511  {
512  return false;
513  }
514  if ((object)this == value)
515  {
516  return true;
517  }
518  if (Length != value.Length)
519  {
520  return false;
521  }
522  return EqualsHelper(this, value);
523  }
524 
532  [SecuritySafeCritical]
533  [__DynamicallyInvokable]
534  public bool Equals(string value, StringComparison comparisonType)
535  {
536  if (comparisonType < StringComparison.CurrentCulture || comparisonType > StringComparison.OrdinalIgnoreCase)
537  {
538  throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType");
539  }
540  if ((object)this == value)
541  {
542  return true;
543  }
544  if (value == null)
545  {
546  return false;
547  }
548  switch (comparisonType)
549  {
550  case StringComparison.CurrentCulture:
551  return CultureInfo.CurrentCulture.CompareInfo.Compare(this, value, CompareOptions.None) == 0;
552  case StringComparison.CurrentCultureIgnoreCase:
553  return CultureInfo.CurrentCulture.CompareInfo.Compare(this, value, CompareOptions.IgnoreCase) == 0;
554  case StringComparison.InvariantCulture:
555  return CultureInfo.InvariantCulture.CompareInfo.Compare(this, value, CompareOptions.None) == 0;
556  case StringComparison.InvariantCultureIgnoreCase:
557  return CultureInfo.InvariantCulture.CompareInfo.Compare(this, value, CompareOptions.IgnoreCase) == 0;
558  case StringComparison.Ordinal:
559  if (Length != value.Length)
560  {
561  return false;
562  }
563  return EqualsHelper(this, value);
564  case StringComparison.OrdinalIgnoreCase:
565  if (Length != value.Length)
566  {
567  return false;
568  }
569  if (IsAscii() && value.IsAscii())
570  {
571  return CompareOrdinalIgnoreCaseHelper(this, value) == 0;
572  }
573  return TextInfo.CompareOrdinalIgnoreCase(this, value) == 0;
574  default:
575  throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType");
576  }
577  }
578 
584  [__DynamicallyInvokable]
585  public static bool Equals(string a, string b)
586  {
587  if ((object)a == b)
588  {
589  return true;
590  }
591  if (a == null || b == null)
592  {
593  return false;
594  }
595  if (a.Length != b.Length)
596  {
597  return false;
598  }
599  return EqualsHelper(a, b);
600  }
601 
610  [SecuritySafeCritical]
611  [__DynamicallyInvokable]
612  public static bool Equals(string a, string b, StringComparison comparisonType)
613  {
614  if (comparisonType < StringComparison.CurrentCulture || comparisonType > StringComparison.OrdinalIgnoreCase)
615  {
616  throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType");
617  }
618  if ((object)a == b)
619  {
620  return true;
621  }
622  if (a == null || b == null)
623  {
624  return false;
625  }
626  switch (comparisonType)
627  {
628  case StringComparison.CurrentCulture:
630  case StringComparison.CurrentCultureIgnoreCase:
631  return CultureInfo.CurrentCulture.CompareInfo.Compare(a, b, CompareOptions.IgnoreCase) == 0;
632  case StringComparison.InvariantCulture:
634  case StringComparison.InvariantCultureIgnoreCase:
635  return CultureInfo.InvariantCulture.CompareInfo.Compare(a, b, CompareOptions.IgnoreCase) == 0;
636  case StringComparison.Ordinal:
637  if (a.Length != b.Length)
638  {
639  return false;
640  }
641  return EqualsHelper(a, b);
642  case StringComparison.OrdinalIgnoreCase:
643  if (a.Length != b.Length)
644  {
645  return false;
646  }
647  if (a.IsAscii() && b.IsAscii())
648  {
649  return CompareOrdinalIgnoreCaseHelper(a, b) == 0;
650  }
651  return TextInfo.CompareOrdinalIgnoreCase(a, b) == 0;
652  default:
653  throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType");
654  }
655  }
656 
662  [__DynamicallyInvokable]
663  public static bool operator ==(string a, string b)
664  {
665  return Equals(a, b);
666  }
667 
673  [__DynamicallyInvokable]
674  public static bool operator !=(string a, string b)
675  {
676  return !Equals(a, b);
677  }
678 
692  [SecuritySafeCritical]
693  [__DynamicallyInvokable]
694  public unsafe void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count)
695  {
696  if (destination == null)
697  {
698  throw new ArgumentNullException("destination");
699  }
700  if (count < 0)
701  {
702  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NegativeCount"));
703  }
704  if (sourceIndex < 0)
705  {
706  throw new ArgumentOutOfRangeException("sourceIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
707  }
708  if (count > Length - sourceIndex)
709  {
710  throw new ArgumentOutOfRangeException("sourceIndex", Environment.GetResourceString("ArgumentOutOfRange_IndexCount"));
711  }
712  if (destinationIndex > destination.Length - count || destinationIndex < 0)
713  {
714  throw new ArgumentOutOfRangeException("destinationIndex", Environment.GetResourceString("ArgumentOutOfRange_IndexCount"));
715  }
716  if (count > 0)
717  {
718  fixed (char* ptr2 = &m_firstChar)
719  {
720  fixed (char* ptr = destination)
721  {
722  wstrcpy(ptr + destinationIndex, ptr2 + sourceIndex, count);
723  }
724  }
725  }
726  }
727 
730  [SecuritySafeCritical]
731  [__DynamicallyInvokable]
732  public unsafe char[] ToCharArray()
733  {
734  int length = Length;
735  char[] array = new char[length];
736  if (length > 0)
737  {
738  fixed (char* smem = &m_firstChar)
739  {
740  char[] array2 = array;
741  fixed (char* dmem = array2)
742  {
743  wstrcpy(dmem, smem, length);
744  }
745  }
746  }
747  return array;
748  }
749 
757  [SecuritySafeCritical]
758  [__DynamicallyInvokable]
759  public unsafe char[] ToCharArray(int startIndex, int length)
760  {
761  if (startIndex < 0 || startIndex > Length || startIndex > Length - length)
762  {
763  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
764  }
765  if (length < 0)
766  {
767  throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_Index"));
768  }
769  char[] array = new char[length];
770  if (length > 0)
771  {
772  fixed (char* ptr = &m_firstChar)
773  {
774  char[] array2 = array;
775  fixed (char* dmem = array2)
776  {
777  wstrcpy(dmem, ptr + startIndex, length);
778  }
779  }
780  }
781  return array;
782  }
783 
788  [__DynamicallyInvokable]
789  public static bool IsNullOrEmpty(string value)
790  {
791  if (value != null)
792  {
793  return value.Length == 0;
794  }
795  return true;
796  }
797 
802  [__DynamicallyInvokable]
803  public static bool IsNullOrWhiteSpace(string value)
804  {
805  if (value == null)
806  {
807  return true;
808  }
809  for (int i = 0; i < value.Length; i++)
810  {
811  if (!char.IsWhiteSpace(value[i]))
812  {
813  return false;
814  }
815  }
816  return true;
817  }
818 
819  [MethodImpl(MethodImplOptions.InternalCall)]
820  [SecurityCritical]
821  internal static extern int InternalMarvin32HashString(string s, int strLen, long additionalEntropy);
822 
823  [SecuritySafeCritical]
824  internal static bool UseRandomizedHashing()
825  {
826  return InternalUseRandomizedHashing();
827  }
828 
829  [DllImport("QCall", CharSet = CharSet.Unicode)]
830  [SecurityCritical]
831  [SuppressUnmanagedCodeSecurity]
832  private static extern bool InternalUseRandomizedHashing();
833 
836  [SecuritySafeCritical]
837  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
838  [__DynamicallyInvokable]
839  public unsafe override int GetHashCode()
840  {
841  if (HashHelpers.s_UseRandomizedStringHashing)
842  {
843  return InternalMarvin32HashString(this, Length, 0L);
844  }
845  fixed (char* ptr = this)
846  {
847  int num = 5381;
848  int num2 = num;
849  char* ptr2 = ptr;
850  int num3;
851  while ((num3 = *ptr2) != 0)
852  {
853  num = (((num << 5) + num) ^ num3);
854  num3 = ptr2[1];
855  if (num3 == 0)
856  {
857  break;
858  }
859  num2 = (((num2 << 5) + num2) ^ num3);
860  ptr2 += 2;
861  }
862  return num + num2 * 1566083941;
863  }
864  }
865 
866  [SecuritySafeCritical]
867  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
868  internal unsafe int GetLegacyNonRandomizedHashCode()
869  {
870  fixed (char* ptr = this)
871  {
872  int num = 5381;
873  int num2 = num;
874  char* ptr2 = ptr;
875  int num3;
876  while ((num3 = *ptr2) != 0)
877  {
878  num = (((num << 5) + num) ^ num3);
879  num3 = ptr2[1];
880  if (num3 == 0)
881  {
882  break;
883  }
884  num2 = (((num2 << 5) + num2) ^ num3);
885  ptr2 += 2;
886  }
887  return num + num2 * 1566083941;
888  }
889  }
890 
894  [__DynamicallyInvokable]
895  public string[] Split(params char[] separator)
896  {
897  return SplitInternal(separator, int.MaxValue, StringSplitOptions.None);
898  }
899 
906  [__DynamicallyInvokable]
907  public string[] Split(char[] separator, int count)
908  {
909  return SplitInternal(separator, count, StringSplitOptions.None);
910  }
911 
919  [ComVisible(false)]
920  [__DynamicallyInvokable]
921  public string[] Split(char[] separator, StringSplitOptions options)
922  {
923  return SplitInternal(separator, int.MaxValue, options);
924  }
925 
936  [ComVisible(false)]
937  [__DynamicallyInvokable]
938  public string[] Split(char[] separator, int count, StringSplitOptions options)
939  {
940  return SplitInternal(separator, count, options);
941  }
942 
943  [ComVisible(false)]
944  internal string[] SplitInternal(char[] separator, int count, StringSplitOptions options)
945  {
946  if (count < 0)
947  {
948  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NegativeCount"));
949  }
950  if (options < StringSplitOptions.None || options > StringSplitOptions.RemoveEmptyEntries)
951  {
952  throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", options));
953  }
954  bool flag = options == StringSplitOptions.RemoveEmptyEntries;
955  if (count == 0 || (flag && Length == 0))
956  {
957  return new string[0];
958  }
959  int[] sepList = new int[Length];
960  int num = MakeSeparatorList(separator, ref sepList);
961  if (num == 0 || count == 1)
962  {
963  return new string[1]
964  {
965  this
966  };
967  }
968  if (flag)
969  {
970  return InternalSplitOmitEmptyEntries(sepList, null, num, count);
971  }
972  return InternalSplitKeepEmptyEntries(sepList, null, num, count);
973  }
974 
982  [ComVisible(false)]
983  [__DynamicallyInvokable]
984  public string[] Split(string[] separator, StringSplitOptions options)
985  {
986  return Split(separator, int.MaxValue, options);
987  }
988 
999  [ComVisible(false)]
1000  [__DynamicallyInvokable]
1001  public string[] Split(string[] separator, int count, StringSplitOptions options)
1002  {
1003  if (count < 0)
1004  {
1005  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NegativeCount"));
1006  }
1007  if (options < StringSplitOptions.None || options > StringSplitOptions.RemoveEmptyEntries)
1008  {
1009  throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)options));
1010  }
1011  bool flag = options == StringSplitOptions.RemoveEmptyEntries;
1012  if (separator == null || separator.Length == 0)
1013  {
1014  return SplitInternal(null, count, options);
1015  }
1016  if (count == 0 || (flag && Length == 0))
1017  {
1018  return new string[0];
1019  }
1020  int[] sepList = new int[Length];
1021  int[] lengthList = new int[Length];
1022  int num = MakeSeparatorList(separator, ref sepList, ref lengthList);
1023  if (num == 0 || count == 1)
1024  {
1025  return new string[1]
1026  {
1027  this
1028  };
1029  }
1030  if (flag)
1031  {
1032  return InternalSplitOmitEmptyEntries(sepList, lengthList, num, count);
1033  }
1034  return InternalSplitKeepEmptyEntries(sepList, lengthList, num, count);
1035  }
1036 
1037  private string[] InternalSplitKeepEmptyEntries(int[] sepList, int[] lengthList, int numReplaces, int count)
1038  {
1039  int num = 0;
1040  int num2 = 0;
1041  count--;
1042  int num3 = (numReplaces < count) ? numReplaces : count;
1043  string[] array = new string[num3 + 1];
1044  for (int i = 0; i < num3; i++)
1045  {
1046  if (num >= Length)
1047  {
1048  break;
1049  }
1050  array[num2++] = Substring(num, sepList[i] - num);
1051  num = sepList[i] + ((lengthList == null) ? 1 : lengthList[i]);
1052  }
1053  if (num < Length && num3 >= 0)
1054  {
1055  array[num2] = Substring(num);
1056  }
1057  else if (num2 == num3)
1058  {
1059  array[num2] = Empty;
1060  }
1061  return array;
1062  }
1063 
1064  private string[] InternalSplitOmitEmptyEntries(int[] sepList, int[] lengthList, int numReplaces, int count)
1065  {
1066  int num = (numReplaces < count) ? (numReplaces + 1) : count;
1067  string[] array = new string[num];
1068  int num2 = 0;
1069  int num3 = 0;
1070  for (int i = 0; i < numReplaces; i++)
1071  {
1072  if (num2 >= Length)
1073  {
1074  break;
1075  }
1076  if (sepList[i] - num2 > 0)
1077  {
1078  array[num3++] = Substring(num2, sepList[i] - num2);
1079  }
1080  num2 = sepList[i] + ((lengthList == null) ? 1 : lengthList[i]);
1081  if (num3 == count - 1)
1082  {
1083  while (i < numReplaces - 1 && num2 == sepList[++i])
1084  {
1085  num2 += ((lengthList == null) ? 1 : lengthList[i]);
1086  }
1087  break;
1088  }
1089  }
1090  if (num2 < Length)
1091  {
1092  array[num3++] = Substring(num2);
1093  }
1094  string[] array2 = array;
1095  if (num3 != num)
1096  {
1097  array2 = new string[num3];
1098  for (int j = 0; j < num3; j++)
1099  {
1100  array2[j] = array[j];
1101  }
1102  }
1103  return array2;
1104  }
1105 
1106  [SecuritySafeCritical]
1107  private unsafe int MakeSeparatorList(char[] separator, ref int[] sepList)
1108  {
1109  int num = 0;
1110  if (separator == null || separator.Length == 0)
1111  {
1112  fixed (char* ptr = &m_firstChar)
1113  {
1114  for (int i = 0; i < Length; i++)
1115  {
1116  if (num >= sepList.Length)
1117  {
1118  break;
1119  }
1120  if (char.IsWhiteSpace(ptr[i]))
1121  {
1122  sepList[num++] = i;
1123  }
1124  }
1125  }
1126  }
1127  else
1128  {
1129  int num3 = sepList.Length;
1130  int num4 = separator.Length;
1131  fixed (char* ptr4 = &m_firstChar)
1132  {
1133  fixed (char* ptr2 = separator)
1134  {
1135  for (int j = 0; j < Length; j++)
1136  {
1137  if (num >= num3)
1138  {
1139  break;
1140  }
1141  char* ptr3 = ptr2;
1142  int num5 = 0;
1143  while (num5 < num4)
1144  {
1145  if (ptr4[j] == *ptr3)
1146  {
1147  sepList[num++] = j;
1148  break;
1149  }
1150  num5++;
1151  ptr3++;
1152  }
1153  }
1154  }
1155  }
1156  }
1157  return num;
1158  }
1159 
1160  [SecuritySafeCritical]
1161  private unsafe int MakeSeparatorList(string[] separators, ref int[] sepList, ref int[] lengthList)
1162  {
1163  int num = 0;
1164  int num2 = sepList.Length;
1165  int num3 = separators.Length;
1166  fixed (char* ptr = &m_firstChar)
1167  {
1168  for (int i = 0; i < Length; i++)
1169  {
1170  if (num >= num2)
1171  {
1172  break;
1173  }
1174  foreach (string text in separators)
1175  {
1176  if (!IsNullOrEmpty(text))
1177  {
1178  int length = text.Length;
1179  if (ptr[i] == text[0] && length <= Length - i && (length == 1 || CompareOrdinal(this, i, text, 0, length) == 0))
1180  {
1181  sepList[num] = i;
1182  lengthList[num] = length;
1183  num++;
1184  i += length - 1;
1185  break;
1186  }
1187  }
1188  }
1189  }
1190  }
1191  return num;
1192  }
1193 
1199  [__DynamicallyInvokable]
1200  public string Substring(int startIndex)
1201  {
1202  return Substring(startIndex, Length - startIndex);
1203  }
1204 
1212  [SecuritySafeCritical]
1213  [__DynamicallyInvokable]
1214  public string Substring(int startIndex, int length)
1215  {
1216  if (startIndex < 0)
1217  {
1218  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndex"));
1219  }
1220  if (startIndex > Length)
1221  {
1222  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndexLargerThanLength"));
1223  }
1224  if (length < 0)
1225  {
1226  throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_NegativeLength"));
1227  }
1228  if (startIndex > Length - length)
1229  {
1230  throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_IndexLength"));
1231  }
1232  if (length == 0)
1233  {
1234  return Empty;
1235  }
1236  if (startIndex == 0 && length == Length)
1237  {
1238  return this;
1239  }
1240  return InternalSubString(startIndex, length);
1241  }
1242 
1243  [SecurityCritical]
1244  private unsafe string InternalSubString(int startIndex, int length)
1245  {
1246  string text = FastAllocateString(length);
1247  fixed (char* dmem = &text.m_firstChar)
1248  {
1249  fixed (char* ptr = &m_firstChar)
1250  {
1251  wstrcpy(dmem, ptr + startIndex, length);
1252  }
1253  }
1254  return text;
1255  }
1256 
1260  [__DynamicallyInvokable]
1261  public string Trim(params char[] trimChars)
1262  {
1263  if (trimChars == null || trimChars.Length == 0)
1264  {
1265  return TrimHelper(2);
1266  }
1267  return TrimHelper(trimChars, 2);
1268  }
1269 
1273  [__DynamicallyInvokable]
1274  public string TrimStart(params char[] trimChars)
1275  {
1276  if (trimChars == null || trimChars.Length == 0)
1277  {
1278  return TrimHelper(0);
1279  }
1280  return TrimHelper(trimChars, 0);
1281  }
1282 
1286  [__DynamicallyInvokable]
1287  public string TrimEnd(params char[] trimChars)
1288  {
1289  if (trimChars == null || trimChars.Length == 0)
1290  {
1291  return TrimHelper(1);
1292  }
1293  return TrimHelper(trimChars, 1);
1294  }
1295 
1301  [MethodImpl(MethodImplOptions.InternalCall)]
1302  [SecurityCritical]
1303  [CLSCompliant(false)]
1304  public unsafe extern String(char* value);
1305 
1314  [MethodImpl(MethodImplOptions.InternalCall)]
1315  [SecurityCritical]
1316  [CLSCompliant(false)]
1317  public unsafe extern String(char* value, int startIndex, int length);
1318 
1327  [MethodImpl(MethodImplOptions.InternalCall)]
1328  [SecurityCritical]
1329  [CLSCompliant(false)]
1330  public unsafe extern String(sbyte* value);
1331 
1343  [MethodImpl(MethodImplOptions.InternalCall)]
1344  [SecurityCritical]
1345  [CLSCompliant(false)]
1346  public unsafe extern String(sbyte* value, int startIndex, int length);
1347 
1360  [MethodImpl(MethodImplOptions.InternalCall)]
1361  [SecurityCritical]
1362  [CLSCompliant(false)]
1363  public unsafe extern String(sbyte* value, int startIndex, int length, Encoding enc);
1364 
1365  [SecurityCritical]
1366  private unsafe static string CreateString(sbyte* value, int startIndex, int length, Encoding enc)
1367  {
1368  if (enc == null)
1369  {
1370  return new string(value, startIndex, length);
1371  }
1372  if (length < 0)
1373  {
1374  throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
1375  }
1376  if (startIndex < 0)
1377  {
1378  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndex"));
1379  }
1380  if (value + startIndex < value)
1381  {
1382  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_PartialWCHAR"));
1383  }
1384  byte[] array = new byte[length];
1385  try
1386  {
1387  Buffer.Memcpy(array, 0, (byte*)value, startIndex, length);
1388  }
1389  catch (NullReferenceException)
1390  {
1391  throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_PartialWCHAR"));
1392  }
1393  return enc.GetString(array);
1394  }
1395 
1396  [SecurityCritical]
1397  internal unsafe static string CreateStringFromEncoding(byte* bytes, int byteLength, Encoding encoding)
1398  {
1399  int charCount = encoding.GetCharCount(bytes, byteLength, null);
1400  if (charCount == 0)
1401  {
1402  return Empty;
1403  }
1404  string text = FastAllocateString(charCount);
1405  fixed (char* chars = &text.m_firstChar)
1406  {
1407  int chars2 = encoding.GetChars(bytes, byteLength, chars, charCount, null);
1408  }
1409  return text;
1410  }
1411 
1412  [SecuritySafeCritical]
1413  internal unsafe int GetBytesFromEncoding(byte* pbNativeBuffer, int cbNativeBuffer, Encoding encoding)
1414  {
1415  fixed (char* chars = &m_firstChar)
1416  {
1417  return encoding.GetBytes(chars, m_stringLength, pbNativeBuffer, cbNativeBuffer);
1418  }
1419  }
1420 
1421  [SecuritySafeCritical]
1422  internal unsafe int ConvertToAnsi(byte* pbNativeBuffer, int cbNativeBuffer, bool fBestFit, bool fThrowOnUnmappableChar)
1423  {
1424  uint flags = (!fBestFit) ? 1024u : 0u;
1425  uint num = 0u;
1426  int num2;
1427  fixed (char* pwzSource = &m_firstChar)
1428  {
1429  num2 = Win32Native.WideCharToMultiByte(0u, flags, pwzSource, Length, pbNativeBuffer, cbNativeBuffer, IntPtr.Zero, fThrowOnUnmappableChar ? new IntPtr(&num) : IntPtr.Zero);
1430  }
1431  if (num != 0)
1432  {
1433  throw new ArgumentException(Environment.GetResourceString("Interop_Marshal_Unmappable_Char"));
1434  }
1435  pbNativeBuffer[num2] = 0;
1436  return num2;
1437  }
1438 
1443  public bool IsNormalized()
1444  {
1445  return IsNormalized(NormalizationForm.FormC);
1446  }
1447 
1453  [SecuritySafeCritical]
1454  public bool IsNormalized(NormalizationForm normalizationForm)
1455  {
1456  if (IsFastSort() && (normalizationForm == NormalizationForm.FormC || normalizationForm == NormalizationForm.FormKC || normalizationForm == NormalizationForm.FormD || normalizationForm == NormalizationForm.FormKD))
1457  {
1458  return true;
1459  }
1460  return Normalization.IsNormalized(this, normalizationForm);
1461  }
1462 
1466  public string Normalize()
1467  {
1468  return Normalize(NormalizationForm.FormC);
1469  }
1470 
1475  [SecuritySafeCritical]
1476  public string Normalize(NormalizationForm normalizationForm)
1477  {
1478  if (IsAscii() && (normalizationForm == NormalizationForm.FormC || normalizationForm == NormalizationForm.FormKC || normalizationForm == NormalizationForm.FormD || normalizationForm == NormalizationForm.FormKD))
1479  {
1480  return this;
1481  }
1482  return Normalization.Normalize(this, normalizationForm);
1483  }
1484 
1485  [MethodImpl(MethodImplOptions.InternalCall)]
1486  [SecurityCritical]
1487  internal static extern string FastAllocateString(int length);
1488 
1489  [SecuritySafeCritical]
1490  private unsafe static void FillStringChecked(string dest, int destPos, string src)
1491  {
1492  if (src.Length > dest.Length - destPos)
1493  {
1494  throw new IndexOutOfRangeException();
1495  }
1496  fixed (char* ptr = &dest.m_firstChar)
1497  {
1498  fixed (char* smem = &src.m_firstChar)
1499  {
1500  wstrcpy(ptr + destPos, smem, src.Length);
1501  }
1502  }
1503  }
1504 
1513  [MethodImpl(MethodImplOptions.InternalCall)]
1514  [SecuritySafeCritical]
1515  [__DynamicallyInvokable]
1516  public extern String(char[] value, int startIndex, int length);
1517 
1520  [MethodImpl(MethodImplOptions.InternalCall)]
1521  [SecuritySafeCritical]
1522  [__DynamicallyInvokable]
1523  public extern String(char[] value);
1524 
1525  [SecurityCritical]
1526  internal unsafe static void wstrcpy(char* dmem, char* smem, int charCount)
1527  {
1528  Buffer.Memcpy((byte*)dmem, (byte*)smem, charCount * 2);
1529  }
1530 
1531  [SecuritySafeCritical]
1532  private unsafe string CtorCharArray(char[] value)
1533  {
1534  if (value != null && value.Length != 0)
1535  {
1536  string text = FastAllocateString(value.Length);
1537  fixed (char* dmem = text)
1538  {
1539  fixed (char* smem = value)
1540  {
1541  wstrcpy(dmem, smem, value.Length);
1542  }
1543  }
1544  return text;
1545  }
1546  return Empty;
1547  }
1548 
1549  [SecuritySafeCritical]
1550  private unsafe string CtorCharArrayStartLength(char[] value, int startIndex, int length)
1551  {
1552  if (value == null)
1553  {
1554  throw new ArgumentNullException("value");
1555  }
1556  if (startIndex < 0)
1557  {
1558  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndex"));
1559  }
1560  if (length < 0)
1561  {
1562  throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_NegativeLength"));
1563  }
1564  if (startIndex > value.Length - length)
1565  {
1566  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
1567  }
1568  if (length > 0)
1569  {
1570  string text = FastAllocateString(length);
1571  fixed (char* dmem = text)
1572  {
1573  fixed (char* ptr = value)
1574  {
1575  wstrcpy(dmem, ptr + startIndex, length);
1576  }
1577  }
1578  return text;
1579  }
1580  return Empty;
1581  }
1582 
1583  [SecuritySafeCritical]
1584  private unsafe string CtorCharCount(char c, int count)
1585  {
1586  if (count > 0)
1587  {
1588  string text = FastAllocateString(count);
1589  if (c != 0)
1590  {
1591  fixed (char* ptr = text)
1592  {
1593  char* ptr2 = ptr;
1594  while (((int)ptr2 & 3) != 0 && count > 0)
1595  {
1596  char* intPtr = ptr2;
1597  ptr2 = intPtr + 1;
1598  *intPtr = c;
1599  count--;
1600  }
1601  uint num = ((uint)c << 16) | c;
1602  if (count >= 4)
1603  {
1604  count -= 4;
1605  do
1606  {
1607  *(uint*)ptr2 = num;
1608  *(uint*)(ptr2 + 2) = num;
1609  ptr2 += 4;
1610  count -= 4;
1611  }
1612  while (count >= 0);
1613  }
1614  if ((count & 2) != 0)
1615  {
1616  *(uint*)ptr2 = num;
1617  ptr2 += 2;
1618  }
1619  if ((count & 1) != 0)
1620  {
1621  *ptr2 = c;
1622  }
1623  }
1624  }
1625  return text;
1626  }
1627  if (count == 0)
1628  {
1629  return Empty;
1630  }
1631  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_MustBeNonNegNum", "count"));
1632  }
1633 
1634  [SecurityCritical]
1635  private unsafe static int wcslen(char* ptr)
1636  {
1637  char* ptr2;
1638  for (ptr2 = ptr; ((int)ptr2 & 3) != 0 && *ptr2 != 0; ptr2++)
1639  {
1640  }
1641  if (*ptr2 != 0)
1642  {
1643  for (; (*ptr2 & ptr2[1]) != 0 || (*ptr2 != 0 && ptr2[1] != 0); ptr2 += 2)
1644  {
1645  }
1646  }
1647  for (; *ptr2 != 0; ptr2++)
1648  {
1649  }
1650  return (int)(ptr2 - ptr);
1651  }
1652 
1653  [SecurityCritical]
1654  private unsafe string CtorCharPtr(char* ptr)
1655  {
1656  if (ptr == null)
1657  {
1658  return Empty;
1659  }
1660  if ((ulong)ptr < 64000uL)
1661  {
1662  throw new ArgumentException(Environment.GetResourceString("Arg_MustBeStringPtrNotAtom"));
1663  }
1664  try
1665  {
1666  int num = wcslen(ptr);
1667  if (num == 0)
1668  {
1669  return Empty;
1670  }
1671  string text = FastAllocateString(num);
1672  try
1673  {
1674  fixed (char* dmem = text)
1675  {
1676  wstrcpy(dmem, ptr, num);
1677  }
1678  }
1679  finally
1680  {
1681  }
1682  return text;
1683  }
1684  catch (NullReferenceException)
1685  {
1686  throw new ArgumentOutOfRangeException("ptr", Environment.GetResourceString("ArgumentOutOfRange_PartialWCHAR"));
1687  }
1688  }
1689 
1690  [SecurityCritical]
1691  private unsafe string CtorCharPtrStartLength(char* ptr, int startIndex, int length)
1692  {
1693  if (length < 0)
1694  {
1695  throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_NegativeLength"));
1696  }
1697  if (startIndex < 0)
1698  {
1699  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndex"));
1700  }
1701  char* ptr2 = ptr + startIndex;
1702  if (ptr2 < ptr)
1703  {
1704  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_PartialWCHAR"));
1705  }
1706  if (length == 0)
1707  {
1708  return Empty;
1709  }
1710  string text = FastAllocateString(length);
1711  try
1712  {
1713  try
1714  {
1715  fixed (char* dmem = text)
1716  {
1717  wstrcpy(dmem, ptr2, length);
1718  }
1719  }
1720  finally
1721  {
1722  }
1723  return text;
1724  }
1725  catch (NullReferenceException)
1726  {
1727  throw new ArgumentOutOfRangeException("ptr", Environment.GetResourceString("ArgumentOutOfRange_PartialWCHAR"));
1728  }
1729  }
1730 
1736  [MethodImpl(MethodImplOptions.InternalCall)]
1737  [SecuritySafeCritical]
1738  [__DynamicallyInvokable]
1739  public extern String(char c, int count);
1740 
1748  [__DynamicallyInvokable]
1749  public static int Compare(string strA, string strB)
1750  {
1751  return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, strB, CompareOptions.None);
1752  }
1753 
1763  [__DynamicallyInvokable]
1764  public static int Compare(string strA, string strB, bool ignoreCase)
1765  {
1766  if (ignoreCase)
1767  {
1768  return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, strB, CompareOptions.IgnoreCase);
1769  }
1770  return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, strB, CompareOptions.None);
1771  }
1772 
1785  [SecuritySafeCritical]
1786  [__DynamicallyInvokable]
1787  public static int Compare(string strA, string strB, StringComparison comparisonType)
1788  {
1789  if ((uint)(comparisonType - 0) > 5u)
1790  {
1791  throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType");
1792  }
1793  if ((object)strA == strB)
1794  {
1795  return 0;
1796  }
1797  if (strA == null)
1798  {
1799  return -1;
1800  }
1801  if (strB == null)
1802  {
1803  return 1;
1804  }
1805  switch (comparisonType)
1806  {
1807  case StringComparison.CurrentCulture:
1808  return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, strB, CompareOptions.None);
1809  case StringComparison.CurrentCultureIgnoreCase:
1810  return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, strB, CompareOptions.IgnoreCase);
1811  case StringComparison.InvariantCulture:
1813  case StringComparison.InvariantCultureIgnoreCase:
1814  return CultureInfo.InvariantCulture.CompareInfo.Compare(strA, strB, CompareOptions.IgnoreCase);
1815  case StringComparison.Ordinal:
1816  if (strA.m_firstChar - strB.m_firstChar != 0)
1817  {
1818  return strA.m_firstChar - strB.m_firstChar;
1819  }
1820  return CompareOrdinalHelper(strA, strB);
1821  case StringComparison.OrdinalIgnoreCase:
1822  if (strA.IsAscii() && strB.IsAscii())
1823  {
1824  return CompareOrdinalIgnoreCaseHelper(strA, strB);
1825  }
1826  return TextInfo.CompareOrdinalIgnoreCase(strA, strB);
1827  default:
1828  throw new NotSupportedException(Environment.GetResourceString("NotSupported_StringComparison"));
1829  }
1830  }
1831 
1845  [__DynamicallyInvokable]
1846  public static int Compare(string strA, string strB, CultureInfo culture, CompareOptions options)
1847  {
1848  if (culture == null)
1849  {
1850  throw new ArgumentNullException("culture");
1851  }
1852  return culture.CompareInfo.Compare(strA, strB, options);
1853  }
1854 
1867  public static int Compare(string strA, string strB, bool ignoreCase, CultureInfo culture)
1868  {
1869  if (culture == null)
1870  {
1871  throw new ArgumentNullException("culture");
1872  }
1873  if (ignoreCase)
1874  {
1875  return culture.CompareInfo.Compare(strA, strB, CompareOptions.IgnoreCase);
1876  }
1877  return culture.CompareInfo.Compare(strA, strB, CompareOptions.None);
1878  }
1879 
1891  [__DynamicallyInvokable]
1892  public static int Compare(string strA, int indexA, string strB, int indexB, int length)
1893  {
1894  int num = length;
1895  int num2 = length;
1896  if (strA != null && strA.Length - indexA < num)
1897  {
1898  num = strA.Length - indexA;
1899  }
1900  if (strB != null && strB.Length - indexB < num2)
1901  {
1902  num2 = strB.Length - indexB;
1903  }
1904  return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, indexA, num, strB, indexB, num2, CompareOptions.None);
1905  }
1906 
1920  public static int Compare(string strA, int indexA, string strB, int indexB, int length, bool ignoreCase)
1921  {
1922  int num = length;
1923  int num2 = length;
1924  if (strA != null && strA.Length - indexA < num)
1925  {
1926  num = strA.Length - indexA;
1927  }
1928  if (strB != null && strB.Length - indexB < num2)
1929  {
1930  num2 = strB.Length - indexB;
1931  }
1932  if (ignoreCase)
1933  {
1934  return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, indexA, num, strB, indexB, num2, CompareOptions.IgnoreCase);
1935  }
1936  return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, indexA, num, strB, indexB, num2, CompareOptions.None);
1937  }
1938 
1955  public static int Compare(string strA, int indexA, string strB, int indexB, int length, bool ignoreCase, CultureInfo culture)
1956  {
1957  if (culture == null)
1958  {
1959  throw new ArgumentNullException("culture");
1960  }
1961  int num = length;
1962  int num2 = length;
1963  if (strA != null && strA.Length - indexA < num)
1964  {
1965  num = strA.Length - indexA;
1966  }
1967  if (strB != null && strB.Length - indexB < num2)
1968  {
1969  num2 = strB.Length - indexB;
1970  }
1971  if (ignoreCase)
1972  {
1973  return culture.CompareInfo.Compare(strA, indexA, num, strB, indexB, num2, CompareOptions.IgnoreCase);
1974  }
1975  return culture.CompareInfo.Compare(strA, indexA, num, strB, indexB, num2, CompareOptions.None);
1976  }
1977 
1995  public static int Compare(string strA, int indexA, string strB, int indexB, int length, CultureInfo culture, CompareOptions options)
1996  {
1997  if (culture == null)
1998  {
1999  throw new ArgumentNullException("culture");
2000  }
2001  int num = length;
2002  int num2 = length;
2003  if (strA != null && strA.Length - indexA < num)
2004  {
2005  num = strA.Length - indexA;
2006  }
2007  if (strB != null && strB.Length - indexB < num2)
2008  {
2009  num2 = strB.Length - indexB;
2010  }
2011  return culture.CompareInfo.Compare(strA, indexA, num, strB, indexB, num2, options);
2012  }
2013 
2028  [SecuritySafeCritical]
2029  [__DynamicallyInvokable]
2030  public static int Compare(string strA, int indexA, string strB, int indexB, int length, StringComparison comparisonType)
2031  {
2032  if (comparisonType < StringComparison.CurrentCulture || comparisonType > StringComparison.OrdinalIgnoreCase)
2033  {
2034  throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType");
2035  }
2036  if (strA == null || strB == null)
2037  {
2038  if ((object)strA == strB)
2039  {
2040  return 0;
2041  }
2042  if (strA != null)
2043  {
2044  return 1;
2045  }
2046  return -1;
2047  }
2048  if (length < 0)
2049  {
2050  throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_NegativeLength"));
2051  }
2052  if (indexA < 0)
2053  {
2054  throw new ArgumentOutOfRangeException("indexA", Environment.GetResourceString("ArgumentOutOfRange_Index"));
2055  }
2056  if (indexB < 0)
2057  {
2058  throw new ArgumentOutOfRangeException("indexB", Environment.GetResourceString("ArgumentOutOfRange_Index"));
2059  }
2060  if (strA.Length - indexA < 0)
2061  {
2062  throw new ArgumentOutOfRangeException("indexA", Environment.GetResourceString("ArgumentOutOfRange_Index"));
2063  }
2064  if (strB.Length - indexB < 0)
2065  {
2066  throw new ArgumentOutOfRangeException("indexB", Environment.GetResourceString("ArgumentOutOfRange_Index"));
2067  }
2068  if (length == 0 || (strA == strB && indexA == indexB))
2069  {
2070  return 0;
2071  }
2072  int num = length;
2073  int num2 = length;
2074  if (strA != null && strA.Length - indexA < num)
2075  {
2076  num = strA.Length - indexA;
2077  }
2078  if (strB != null && strB.Length - indexB < num2)
2079  {
2080  num2 = strB.Length - indexB;
2081  }
2082  switch (comparisonType)
2083  {
2084  case StringComparison.CurrentCulture:
2085  return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, indexA, num, strB, indexB, num2, CompareOptions.None);
2086  case StringComparison.CurrentCultureIgnoreCase:
2087  return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, indexA, num, strB, indexB, num2, CompareOptions.IgnoreCase);
2088  case StringComparison.InvariantCulture:
2089  return CultureInfo.InvariantCulture.CompareInfo.Compare(strA, indexA, num, strB, indexB, num2, CompareOptions.None);
2090  case StringComparison.InvariantCultureIgnoreCase:
2091  return CultureInfo.InvariantCulture.CompareInfo.Compare(strA, indexA, num, strB, indexB, num2, CompareOptions.IgnoreCase);
2092  case StringComparison.Ordinal:
2093  return nativeCompareOrdinalEx(strA, indexA, strB, indexB, length);
2094  case StringComparison.OrdinalIgnoreCase:
2095  return TextInfo.CompareOrdinalIgnoreCaseEx(strA, indexA, strB, indexB, num, num2);
2096  default:
2097  throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"));
2098  }
2099  }
2100 
2107  public int CompareTo(object value)
2108  {
2109  if (value == null)
2110  {
2111  return 1;
2112  }
2113  if (!(value is string))
2114  {
2115  throw new ArgumentException(Environment.GetResourceString("Arg_MustBeString"));
2116  }
2117  return Compare(this, (string)value, StringComparison.CurrentCulture);
2118  }
2119 
2124  [__DynamicallyInvokable]
2125  public int CompareTo(string strB)
2126  {
2127  if (strB == null)
2128  {
2129  return 1;
2130  }
2131  return CultureInfo.CurrentCulture.CompareInfo.Compare(this, strB, CompareOptions.None);
2132  }
2133 
2141  [__DynamicallyInvokable]
2142  public static int CompareOrdinal(string strA, string strB)
2143  {
2144  if ((object)strA == strB)
2145  {
2146  return 0;
2147  }
2148  if (strA == null)
2149  {
2150  return -1;
2151  }
2152  if (strB == null)
2153  {
2154  return 1;
2155  }
2156  if (strA.m_firstChar - strB.m_firstChar != 0)
2157  {
2158  return strA.m_firstChar - strB.m_firstChar;
2159  }
2160  return CompareOrdinalHelper(strA, strB);
2161  }
2162 
2174  [SecuritySafeCritical]
2175  [__DynamicallyInvokable]
2176  public static int CompareOrdinal(string strA, int indexA, string strB, int indexB, int length)
2177  {
2178  if (strA == null || strB == null)
2179  {
2180  if ((object)strA == strB)
2181  {
2182  return 0;
2183  }
2184  if (strA != null)
2185  {
2186  return 1;
2187  }
2188  return -1;
2189  }
2190  return nativeCompareOrdinalEx(strA, indexA, strB, indexB, length);
2191  }
2192 
2199  [__DynamicallyInvokable]
2200  public bool Contains(string value)
2201  {
2202  return IndexOf(value, StringComparison.Ordinal) >= 0;
2203  }
2204 
2211  [__DynamicallyInvokable]
2212  public bool EndsWith(string value)
2213  {
2214  return EndsWith(value, StringComparison.CurrentCulture);
2215  }
2216 
2226  [SecuritySafeCritical]
2227  [ComVisible(false)]
2228  [__DynamicallyInvokable]
2229  public bool EndsWith(string value, StringComparison comparisonType)
2230  {
2231  if (value == null)
2232  {
2233  throw new ArgumentNullException("value");
2234  }
2235  if (comparisonType < StringComparison.CurrentCulture || comparisonType > StringComparison.OrdinalIgnoreCase)
2236  {
2237  throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType");
2238  }
2239  if ((object)this == value)
2240  {
2241  return true;
2242  }
2243  if (value.Length == 0)
2244  {
2245  return true;
2246  }
2247  switch (comparisonType)
2248  {
2249  case StringComparison.CurrentCulture:
2250  return CultureInfo.CurrentCulture.CompareInfo.IsSuffix(this, value, CompareOptions.None);
2251  case StringComparison.CurrentCultureIgnoreCase:
2252  return CultureInfo.CurrentCulture.CompareInfo.IsSuffix(this, value, CompareOptions.IgnoreCase);
2253  case StringComparison.InvariantCulture:
2255  case StringComparison.InvariantCultureIgnoreCase:
2256  return CultureInfo.InvariantCulture.CompareInfo.IsSuffix(this, value, CompareOptions.IgnoreCase);
2257  case StringComparison.Ordinal:
2258  if (Length >= value.Length)
2259  {
2260  return nativeCompareOrdinalEx(this, Length - value.Length, value, 0, value.Length) == 0;
2261  }
2262  return false;
2263  case StringComparison.OrdinalIgnoreCase:
2264  if (Length >= value.Length)
2265  {
2266  return TextInfo.CompareOrdinalIgnoreCaseEx(this, Length - value.Length, value, 0, value.Length, value.Length) == 0;
2267  }
2268  return false;
2269  default:
2270  throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType");
2271  }
2272  }
2273 
2283  public bool EndsWith(string value, bool ignoreCase, CultureInfo culture)
2284  {
2285  if (value == null)
2286  {
2287  throw new ArgumentNullException("value");
2288  }
2289  if ((object)this == value)
2290  {
2291  return true;
2292  }
2293  CultureInfo cultureInfo = (culture != null) ? culture : CultureInfo.CurrentCulture;
2294  return cultureInfo.CompareInfo.IsSuffix(this, value, ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None);
2295  }
2296 
2297  internal bool EndsWith(char value)
2298  {
2299  int length = Length;
2300  if (length != 0 && this[length - 1] == value)
2301  {
2302  return true;
2303  }
2304  return false;
2305  }
2306 
2310  [__DynamicallyInvokable]
2311  public int IndexOf(char value)
2312  {
2313  return IndexOf(value, 0, Length);
2314  }
2315 
2322  [__DynamicallyInvokable]
2323  public int IndexOf(char value, int startIndex)
2324  {
2325  return IndexOf(value, startIndex, Length - startIndex);
2326  }
2327 
2337  [MethodImpl(MethodImplOptions.InternalCall)]
2338  [SecuritySafeCritical]
2339  [__DynamicallyInvokable]
2340  public extern int IndexOf(char value, int startIndex, int count);
2341 
2347  [__DynamicallyInvokable]
2348  public int IndexOfAny(char[] anyOf)
2349  {
2350  return IndexOfAny(anyOf, 0, Length);
2351  }
2352 
2362  [__DynamicallyInvokable]
2363  public int IndexOfAny(char[] anyOf, int startIndex)
2364  {
2365  return IndexOfAny(anyOf, startIndex, Length - startIndex);
2366  }
2367 
2378  [MethodImpl(MethodImplOptions.InternalCall)]
2379  [SecuritySafeCritical]
2380  [__DynamicallyInvokable]
2381  public extern int IndexOfAny(char[] anyOf, int startIndex, int count);
2382 
2388  [__DynamicallyInvokable]
2389  public int IndexOf(string value)
2390  {
2391  return IndexOf(value, StringComparison.CurrentCulture);
2392  }
2393 
2402  [__DynamicallyInvokable]
2403  public int IndexOf(string value, int startIndex)
2404  {
2405  return IndexOf(value, startIndex, StringComparison.CurrentCulture);
2406  }
2407 
2419  [__DynamicallyInvokable]
2420  public int IndexOf(string value, int startIndex, int count)
2421  {
2422  if (startIndex < 0 || startIndex > Length)
2423  {
2424  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
2425  }
2426  if (count < 0 || count > Length - startIndex)
2427  {
2428  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
2429  }
2430  return IndexOf(value, startIndex, count, StringComparison.CurrentCulture);
2431  }
2432 
2441  [__DynamicallyInvokable]
2442  public int IndexOf(string value, StringComparison comparisonType)
2443  {
2444  return IndexOf(value, 0, Length, comparisonType);
2445  }
2446 
2458  [__DynamicallyInvokable]
2459  public int IndexOf(string value, int startIndex, StringComparison comparisonType)
2460  {
2461  return IndexOf(value, startIndex, Length - startIndex, comparisonType);
2462  }
2463 
2478  [SecuritySafeCritical]
2479  [__DynamicallyInvokable]
2480  public int IndexOf(string value, int startIndex, int count, StringComparison comparisonType)
2481  {
2482  if (value == null)
2483  {
2484  throw new ArgumentNullException("value");
2485  }
2486  if (startIndex < 0 || startIndex > Length)
2487  {
2488  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
2489  }
2490  if (count < 0 || startIndex > Length - count)
2491  {
2492  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
2493  }
2494  switch (comparisonType)
2495  {
2496  case StringComparison.CurrentCulture:
2497  return CultureInfo.CurrentCulture.CompareInfo.IndexOf(this, value, startIndex, count, CompareOptions.None);
2498  case StringComparison.CurrentCultureIgnoreCase:
2499  return CultureInfo.CurrentCulture.CompareInfo.IndexOf(this, value, startIndex, count, CompareOptions.IgnoreCase);
2500  case StringComparison.InvariantCulture:
2501  return CultureInfo.InvariantCulture.CompareInfo.IndexOf(this, value, startIndex, count, CompareOptions.None);
2502  case StringComparison.InvariantCultureIgnoreCase:
2503  return CultureInfo.InvariantCulture.CompareInfo.IndexOf(this, value, startIndex, count, CompareOptions.IgnoreCase);
2504  case StringComparison.Ordinal:
2505  return CultureInfo.InvariantCulture.CompareInfo.IndexOf(this, value, startIndex, count, CompareOptions.Ordinal);
2506  case StringComparison.OrdinalIgnoreCase:
2507  if (value.IsAscii() && IsAscii())
2508  {
2509  return CultureInfo.InvariantCulture.CompareInfo.IndexOf(this, value, startIndex, count, CompareOptions.IgnoreCase);
2510  }
2511  return TextInfo.IndexOfStringOrdinalIgnoreCase(this, value, startIndex, count);
2512  default:
2513  throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType");
2514  }
2515  }
2516 
2520  [__DynamicallyInvokable]
2521  public int LastIndexOf(char value)
2522  {
2523  return LastIndexOf(value, Length - 1, Length);
2524  }
2525 
2532  [__DynamicallyInvokable]
2533  public int LastIndexOf(char value, int startIndex)
2534  {
2535  return LastIndexOf(value, startIndex, startIndex + 1);
2536  }
2537 
2546  [MethodImpl(MethodImplOptions.InternalCall)]
2547  [SecuritySafeCritical]
2548  [__DynamicallyInvokable]
2549  public extern int LastIndexOf(char value, int startIndex, int count);
2550 
2556  [__DynamicallyInvokable]
2557  public int LastIndexOfAny(char[] anyOf)
2558  {
2559  return LastIndexOfAny(anyOf, Length - 1, Length);
2560  }
2561 
2570  [__DynamicallyInvokable]
2571  public int LastIndexOfAny(char[] anyOf, int startIndex)
2572  {
2573  return LastIndexOfAny(anyOf, startIndex, startIndex + 1);
2574  }
2575 
2586  [MethodImpl(MethodImplOptions.InternalCall)]
2587  [SecuritySafeCritical]
2588  [__DynamicallyInvokable]
2589  public extern int LastIndexOfAny(char[] anyOf, int startIndex, int count);
2590 
2596  [__DynamicallyInvokable]
2597  public int LastIndexOf(string value)
2598  {
2599  return LastIndexOf(value, Length - 1, Length, StringComparison.CurrentCulture);
2600  }
2601 
2610  [__DynamicallyInvokable]
2611  public int LastIndexOf(string value, int startIndex)
2612  {
2613  return LastIndexOf(value, startIndex, startIndex + 1, StringComparison.CurrentCulture);
2614  }
2615 
2628  [__DynamicallyInvokable]
2629  public int LastIndexOf(string value, int startIndex, int count)
2630  {
2631  if (count < 0)
2632  {
2633  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
2634  }
2635  return LastIndexOf(value, startIndex, count, StringComparison.CurrentCulture);
2636  }
2637 
2646  [__DynamicallyInvokable]
2647  public int LastIndexOf(string value, StringComparison comparisonType)
2648  {
2649  return LastIndexOf(value, Length - 1, Length, comparisonType);
2650  }
2651 
2663  [__DynamicallyInvokable]
2664  public int LastIndexOf(string value, int startIndex, StringComparison comparisonType)
2665  {
2666  return LastIndexOf(value, startIndex, startIndex + 1, comparisonType);
2667  }
2668 
2684  [SecuritySafeCritical]
2685  [__DynamicallyInvokable]
2686  public int LastIndexOf(string value, int startIndex, int count, StringComparison comparisonType)
2687  {
2688  if (value == null)
2689  {
2690  throw new ArgumentNullException("value");
2691  }
2692  if (Length == 0 && (startIndex == -1 || startIndex == 0))
2693  {
2694  if (value.Length != 0)
2695  {
2696  return -1;
2697  }
2698  return 0;
2699  }
2700  if (startIndex < 0 || startIndex > Length)
2701  {
2702  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
2703  }
2704  if (startIndex == Length)
2705  {
2706  startIndex--;
2707  if (count > 0)
2708  {
2709  count--;
2710  }
2711  if (value.Length == 0 && count >= 0 && startIndex - count + 1 >= 0)
2712  {
2713  return startIndex;
2714  }
2715  }
2716  if (count < 0 || startIndex - count + 1 < 0)
2717  {
2718  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
2719  }
2720  switch (comparisonType)
2721  {
2722  case StringComparison.CurrentCulture:
2723  return CultureInfo.CurrentCulture.CompareInfo.LastIndexOf(this, value, startIndex, count, CompareOptions.None);
2724  case StringComparison.CurrentCultureIgnoreCase:
2725  return CultureInfo.CurrentCulture.CompareInfo.LastIndexOf(this, value, startIndex, count, CompareOptions.IgnoreCase);
2726  case StringComparison.InvariantCulture:
2727  return CultureInfo.InvariantCulture.CompareInfo.LastIndexOf(this, value, startIndex, count, CompareOptions.None);
2728  case StringComparison.InvariantCultureIgnoreCase:
2729  return CultureInfo.InvariantCulture.CompareInfo.LastIndexOf(this, value, startIndex, count, CompareOptions.IgnoreCase);
2730  case StringComparison.Ordinal:
2731  return CultureInfo.InvariantCulture.CompareInfo.LastIndexOf(this, value, startIndex, count, CompareOptions.Ordinal);
2732  case StringComparison.OrdinalIgnoreCase:
2733  if (value.IsAscii() && IsAscii())
2734  {
2735  return CultureInfo.InvariantCulture.CompareInfo.LastIndexOf(this, value, startIndex, count, CompareOptions.IgnoreCase);
2736  }
2737  return TextInfo.LastIndexOfStringOrdinalIgnoreCase(this, value, startIndex, count);
2738  default:
2739  throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType");
2740  }
2741  }
2742 
2748  [__DynamicallyInvokable]
2749  public string PadLeft(int totalWidth)
2750  {
2751  return PadHelper(totalWidth, ' ', isRightPadded: false);
2752  }
2753 
2760  [__DynamicallyInvokable]
2761  public string PadLeft(int totalWidth, char paddingChar)
2762  {
2763  return PadHelper(totalWidth, paddingChar, isRightPadded: false);
2764  }
2765 
2771  [__DynamicallyInvokable]
2772  public string PadRight(int totalWidth)
2773  {
2774  return PadHelper(totalWidth, ' ', isRightPadded: true);
2775  }
2776 
2783  [__DynamicallyInvokable]
2784  public string PadRight(int totalWidth, char paddingChar)
2785  {
2786  return PadHelper(totalWidth, paddingChar, isRightPadded: true);
2787  }
2788 
2789  [MethodImpl(MethodImplOptions.InternalCall)]
2790  [SecuritySafeCritical]
2791  private extern string PadHelper(int totalWidth, char paddingChar, bool isRightPadded);
2792 
2799  [__DynamicallyInvokable]
2800  public bool StartsWith(string value)
2801  {
2802  if (value == null)
2803  {
2804  throw new ArgumentNullException("value");
2805  }
2806  return StartsWith(value, StringComparison.CurrentCulture);
2807  }
2808 
2818  [SecuritySafeCritical]
2819  [ComVisible(false)]
2820  [__DynamicallyInvokable]
2821  public bool StartsWith(string value, StringComparison comparisonType)
2822  {
2823  if (value == null)
2824  {
2825  throw new ArgumentNullException("value");
2826  }
2827  if (comparisonType < StringComparison.CurrentCulture || comparisonType > StringComparison.OrdinalIgnoreCase)
2828  {
2829  throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType");
2830  }
2831  if ((object)this == value)
2832  {
2833  return true;
2834  }
2835  if (value.Length == 0)
2836  {
2837  return true;
2838  }
2839  switch (comparisonType)
2840  {
2841  case StringComparison.CurrentCulture:
2842  return CultureInfo.CurrentCulture.CompareInfo.IsPrefix(this, value, CompareOptions.None);
2843  case StringComparison.CurrentCultureIgnoreCase:
2844  return CultureInfo.CurrentCulture.CompareInfo.IsPrefix(this, value, CompareOptions.IgnoreCase);
2845  case StringComparison.InvariantCulture:
2847  case StringComparison.InvariantCultureIgnoreCase:
2848  return CultureInfo.InvariantCulture.CompareInfo.IsPrefix(this, value, CompareOptions.IgnoreCase);
2849  case StringComparison.Ordinal:
2850  if (Length < value.Length)
2851  {
2852  return false;
2853  }
2854  return nativeCompareOrdinalEx(this, 0, value, 0, value.Length) == 0;
2855  case StringComparison.OrdinalIgnoreCase:
2856  if (Length < value.Length)
2857  {
2858  return false;
2859  }
2860  return TextInfo.CompareOrdinalIgnoreCaseEx(this, 0, value, 0, value.Length, value.Length) == 0;
2861  default:
2862  throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType");
2863  }
2864  }
2865 
2875  public bool StartsWith(string value, bool ignoreCase, CultureInfo culture)
2876  {
2877  if (value == null)
2878  {
2879  throw new ArgumentNullException("value");
2880  }
2881  if ((object)this == value)
2882  {
2883  return true;
2884  }
2885  CultureInfo cultureInfo = (culture != null) ? culture : CultureInfo.CurrentCulture;
2886  return cultureInfo.CompareInfo.IsPrefix(this, value, ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None);
2887  }
2888 
2891  [__DynamicallyInvokable]
2892  public string ToLower()
2893  {
2895  }
2896 
2902  public string ToLower(CultureInfo culture)
2903  {
2904  if (culture == null)
2905  {
2906  throw new ArgumentNullException("culture");
2907  }
2908  return culture.TextInfo.ToLower(this);
2909  }
2910 
2913  [__DynamicallyInvokable]
2914  public string ToLowerInvariant()
2915  {
2917  }
2918 
2921  [__DynamicallyInvokable]
2922  public string ToUpper()
2923  {
2925  }
2926 
2932  public string ToUpper(CultureInfo culture)
2933  {
2934  if (culture == null)
2935  {
2936  throw new ArgumentNullException("culture");
2937  }
2938  return culture.TextInfo.ToUpper(this);
2939  }
2940 
2943  [__DynamicallyInvokable]
2944  public string ToUpperInvariant()
2945  {
2947  }
2948 
2951  [__DynamicallyInvokable]
2952  public override string ToString()
2953  {
2954  return this;
2955  }
2956 
2960  public string ToString(IFormatProvider provider)
2961  {
2962  return this;
2963  }
2964 
2967  public object Clone()
2968  {
2969  return this;
2970  }
2971 
2972  private static bool IsBOMWhitespace(char c)
2973  {
2974  return false;
2975  }
2976 
2979  [__DynamicallyInvokable]
2980  public string Trim()
2981  {
2982  return TrimHelper(2);
2983  }
2984 
2985  [SecuritySafeCritical]
2986  private string TrimHelper(int trimType)
2987  {
2988  int num = Length - 1;
2989  int i = 0;
2990  if (trimType != 1)
2991  {
2992  for (i = 0; i < Length && (char.IsWhiteSpace(this[i]) || IsBOMWhitespace(this[i])); i++)
2993  {
2994  }
2995  }
2996  if (trimType != 0)
2997  {
2998  num = Length - 1;
2999  while (num >= i && (char.IsWhiteSpace(this[num]) || IsBOMWhitespace(this[i])))
3000  {
3001  num--;
3002  }
3003  }
3004  return CreateTrimmedString(i, num);
3005  }
3006 
3007  [SecuritySafeCritical]
3008  private string TrimHelper(char[] trimChars, int trimType)
3009  {
3010  int num = Length - 1;
3011  int i = 0;
3012  if (trimType != 1)
3013  {
3014  for (i = 0; i < Length; i++)
3015  {
3016  int num2 = 0;
3017  char c = this[i];
3018  for (num2 = 0; num2 < trimChars.Length && trimChars[num2] != c; num2++)
3019  {
3020  }
3021  if (num2 == trimChars.Length)
3022  {
3023  break;
3024  }
3025  }
3026  }
3027  if (trimType != 0)
3028  {
3029  for (num = Length - 1; num >= i; num--)
3030  {
3031  int num3 = 0;
3032  char c2 = this[num];
3033  for (num3 = 0; num3 < trimChars.Length && trimChars[num3] != c2; num3++)
3034  {
3035  }
3036  if (num3 == trimChars.Length)
3037  {
3038  break;
3039  }
3040  }
3041  }
3042  return CreateTrimmedString(i, num);
3043  }
3044 
3045  [SecurityCritical]
3046  private string CreateTrimmedString(int start, int end)
3047  {
3048  int num = end - start + 1;
3049  if (num == Length)
3050  {
3051  return this;
3052  }
3053  if (num == 0)
3054  {
3055  return Empty;
3056  }
3057  return InternalSubString(start, num);
3058  }
3059 
3069  [SecuritySafeCritical]
3070  [__DynamicallyInvokable]
3071  public unsafe string Insert(int startIndex, string value)
3072  {
3073  if (value == null)
3074  {
3075  throw new ArgumentNullException("value");
3076  }
3077  if (startIndex < 0 || startIndex > Length)
3078  {
3079  throw new ArgumentOutOfRangeException("startIndex");
3080  }
3081  int length = Length;
3082  int length2 = value.Length;
3083  int num = length + length2;
3084  if (num == 0)
3085  {
3086  return Empty;
3087  }
3088  string text = FastAllocateString(num);
3089  fixed (char* ptr2 = &m_firstChar)
3090  {
3091  fixed (char* smem = &value.m_firstChar)
3092  {
3093  fixed (char* ptr = &text.m_firstChar)
3094  {
3095  wstrcpy(ptr, ptr2, startIndex);
3096  wstrcpy(ptr + startIndex, smem, length2);
3097  wstrcpy(ptr + startIndex + length2, ptr2 + startIndex, length - startIndex);
3098  }
3099  }
3100  }
3101  return text;
3102  }
3103 
3104  [MethodImpl(MethodImplOptions.InternalCall)]
3105  [SecuritySafeCritical]
3106  private extern string ReplaceInternal(char oldChar, char newChar);
3107 
3112  [__DynamicallyInvokable]
3113  public string Replace(char oldChar, char newChar)
3114  {
3115  return ReplaceInternal(oldChar, newChar);
3116  }
3117 
3118  [MethodImpl(MethodImplOptions.InternalCall)]
3119  [SecuritySafeCritical]
3120  private extern string ReplaceInternal(string oldValue, string newValue);
3121 
3130  [__DynamicallyInvokable]
3131  public string Replace(string oldValue, string newValue)
3132  {
3133  if (oldValue == null)
3134  {
3135  throw new ArgumentNullException("oldValue");
3136  }
3137  return ReplaceInternal(oldValue, newValue);
3138  }
3139 
3147  [SecuritySafeCritical]
3148  [__DynamicallyInvokable]
3149  public unsafe string Remove(int startIndex, int count)
3150  {
3151  if (startIndex < 0)
3152  {
3153  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndex"));
3154  }
3155  if (count < 0)
3156  {
3157  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NegativeCount"));
3158  }
3159  if (count > Length - startIndex)
3160  {
3161  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_IndexCount"));
3162  }
3163  int num = Length - count;
3164  if (num == 0)
3165  {
3166  return Empty;
3167  }
3168  string text = FastAllocateString(num);
3169  fixed (char* ptr2 = &m_firstChar)
3170  {
3171  fixed (char* ptr = &text.m_firstChar)
3172  {
3173  wstrcpy(ptr, ptr2, startIndex);
3174  wstrcpy(ptr + startIndex, ptr2 + startIndex + count, num - startIndex);
3175  }
3176  }
3177  return text;
3178  }
3179 
3187  [__DynamicallyInvokable]
3188  public string Remove(int startIndex)
3189  {
3190  if (startIndex < 0)
3191  {
3192  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndex"));
3193  }
3194  if (startIndex >= Length)
3195  {
3196  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndexLessThanLength"));
3197  }
3198  return Substring(0, startIndex);
3199  }
3200 
3208  [__DynamicallyInvokable]
3209  public static string Format(string format, object arg0)
3210  {
3211  return FormatHelper(null, format, new ParamsArray(arg0));
3212  }
3213 
3223  [__DynamicallyInvokable]
3224  public static string Format(string format, object arg0, object arg1)
3225  {
3226  return FormatHelper(null, format, new ParamsArray(arg0, arg1));
3227  }
3228 
3239  [__DynamicallyInvokable]
3240  public static string Format(string format, object arg0, object arg1, object arg2)
3241  {
3242  return FormatHelper(null, format, new ParamsArray(arg0, arg1, arg2));
3243  }
3244 
3253  [__DynamicallyInvokable]
3254  public static string Format(string format, params object[] args)
3255  {
3256  if (args == null)
3257  {
3258  throw new ArgumentNullException((format == null) ? "format" : "args");
3259  }
3260  return FormatHelper(null, format, new ParamsArray(args));
3261  }
3262 
3272  [__DynamicallyInvokable]
3273  public static string Format(IFormatProvider provider, string format, object arg0)
3274  {
3275  return FormatHelper(provider, format, new ParamsArray(arg0));
3276  }
3277 
3288  [__DynamicallyInvokable]
3289  public static string Format(IFormatProvider provider, string format, object arg0, object arg1)
3290  {
3291  return FormatHelper(provider, format, new ParamsArray(arg0, arg1));
3292  }
3293 
3305  [__DynamicallyInvokable]
3306  public static string Format(IFormatProvider provider, string format, object arg0, object arg1, object arg2)
3307  {
3308  return FormatHelper(provider, format, new ParamsArray(arg0, arg1, arg2));
3309  }
3310 
3320  [__DynamicallyInvokable]
3321  public static string Format(IFormatProvider provider, string format, params object[] args)
3322  {
3323  if (args == null)
3324  {
3325  throw new ArgumentNullException((format == null) ? "format" : "args");
3326  }
3327  return FormatHelper(provider, format, new ParamsArray(args));
3328  }
3329 
3330  private static string FormatHelper(IFormatProvider provider, string format, ParamsArray args)
3331  {
3332  if (format == null)
3333  {
3334  throw new ArgumentNullException("format");
3335  }
3336  return StringBuilderCache.GetStringAndRelease(StringBuilderCache.Acquire(format.Length + args.Length * 8).AppendFormatHelper(provider, format, args));
3337  }
3338 
3344  [SecuritySafeCritical]
3345  public unsafe static string Copy(string str)
3346  {
3347  if (str == null)
3348  {
3349  throw new ArgumentNullException("str");
3350  }
3351  int length = str.Length;
3352  string text = FastAllocateString(length);
3353  fixed (char* dmem = &text.m_firstChar)
3354  {
3355  fixed (char* smem = &str.m_firstChar)
3356  {
3357  wstrcpy(dmem, smem, length);
3358  }
3359  }
3360  return text;
3361  }
3362 
3366  [__DynamicallyInvokable]
3367  public static string Concat(object arg0)
3368  {
3369  if (arg0 == null)
3370  {
3371  return Empty;
3372  }
3373  return arg0.ToString();
3374  }
3375 
3380  [__DynamicallyInvokable]
3381  public static string Concat(object arg0, object arg1)
3382  {
3383  if (arg0 == null)
3384  {
3385  arg0 = Empty;
3386  }
3387  if (arg1 == null)
3388  {
3389  arg1 = Empty;
3390  }
3391  return arg0.ToString() + arg1.ToString();
3392  }
3393 
3399  [__DynamicallyInvokable]
3400  public static string Concat(object arg0, object arg1, object arg2)
3401  {
3402  if (arg0 == null)
3403  {
3404  arg0 = Empty;
3405  }
3406  if (arg1 == null)
3407  {
3408  arg1 = Empty;
3409  }
3410  if (arg2 == null)
3411  {
3412  arg2 = Empty;
3413  }
3414  return arg0.ToString() + arg1.ToString() + arg2.ToString();
3415  }
3416 
3417  [CLSCompliant(false)]
3418  public static string Concat(object arg0, object arg1, object arg2, object arg3, __arglist)
3419  {
3420  ArgIterator argIterator = new ArgIterator(__arglist);
3421  int num = argIterator.GetRemainingCount() + 4;
3422  object[] array = new object[num];
3423  array[0] = arg0;
3424  array[1] = arg1;
3425  array[2] = arg2;
3426  array[3] = arg3;
3427  for (int i = 4; i < num; i++)
3428  {
3429  array[i] = TypedReference.ToObject(argIterator.GetNextArg());
3430  }
3431  return Concat(array);
3432  }
3433 
3440  [__DynamicallyInvokable]
3441  public static string Concat(params object[] args)
3442  {
3443  if (args == null)
3444  {
3445  throw new ArgumentNullException("args");
3446  }
3447  string[] array = new string[args.Length];
3448  int num = 0;
3449  for (int i = 0; i < args.Length; i++)
3450  {
3451  object obj = args[i];
3452  array[i] = ((obj == null) ? Empty : obj.ToString());
3453  if (array[i] == null)
3454  {
3455  array[i] = Empty;
3456  }
3457  num += array[i].Length;
3458  if (num < 0)
3459  {
3460  throw new OutOfMemoryException();
3461  }
3462  }
3463  return ConcatArray(array, num);
3464  }
3465 
3472  [ComVisible(false)]
3473  [__DynamicallyInvokable]
3474  public static string Concat<T>(IEnumerable<T> values)
3475  {
3476  if (values == null)
3477  {
3478  throw new ArgumentNullException("values");
3479  }
3480  StringBuilder stringBuilder = StringBuilderCache.Acquire();
3481  using (IEnumerator<T> enumerator = values.GetEnumerator())
3482  {
3483  while (enumerator.MoveNext())
3484  {
3485  if (enumerator.Current != null)
3486  {
3487  string text = enumerator.Current.ToString();
3488  if (text != null)
3489  {
3490  stringBuilder.Append(text);
3491  }
3492  }
3493  }
3494  }
3495  return StringBuilderCache.GetStringAndRelease(stringBuilder);
3496  }
3497 
3503  [ComVisible(false)]
3504  [__DynamicallyInvokable]
3505  public static string Concat(IEnumerable<string> values)
3506  {
3507  if (values == null)
3508  {
3509  throw new ArgumentNullException("values");
3510  }
3511  StringBuilder stringBuilder = StringBuilderCache.Acquire();
3512  using (IEnumerator<string> enumerator = values.GetEnumerator())
3513  {
3514  while (enumerator.MoveNext())
3515  {
3516  if (enumerator.Current != null)
3517  {
3518  stringBuilder.Append(enumerator.Current);
3519  }
3520  }
3521  }
3522  return StringBuilderCache.GetStringAndRelease(stringBuilder);
3523  }
3524 
3529  [SecuritySafeCritical]
3530  [__DynamicallyInvokable]
3531  public static string Concat(string str0, string str1)
3532  {
3533  if (IsNullOrEmpty(str0))
3534  {
3535  if (IsNullOrEmpty(str1))
3536  {
3537  return Empty;
3538  }
3539  return str1;
3540  }
3541  if (IsNullOrEmpty(str1))
3542  {
3543  return str0;
3544  }
3545  int length = str0.Length;
3546  string text = FastAllocateString(length + str1.Length);
3547  FillStringChecked(text, 0, str0);
3548  FillStringChecked(text, length, str1);
3549  return text;
3550  }
3551 
3557  [SecuritySafeCritical]
3558  [__DynamicallyInvokable]
3559  public static string Concat(string str0, string str1, string str2)
3560  {
3561  if (str0 == null && str1 == null && str2 == null)
3562  {
3563  return Empty;
3564  }
3565  if (str0 == null)
3566  {
3567  str0 = Empty;
3568  }
3569  if (str1 == null)
3570  {
3571  str1 = Empty;
3572  }
3573  if (str2 == null)
3574  {
3575  str2 = Empty;
3576  }
3577  int length = str0.Length + str1.Length + str2.Length;
3578  string text = FastAllocateString(length);
3579  FillStringChecked(text, 0, str0);
3580  FillStringChecked(text, str0.Length, str1);
3581  FillStringChecked(text, str0.Length + str1.Length, str2);
3582  return text;
3583  }
3584 
3591  [SecuritySafeCritical]
3592  [__DynamicallyInvokable]
3593  public static string Concat(string str0, string str1, string str2, string str3)
3594  {
3595  if (str0 == null && str1 == null && str2 == null && str3 == null)
3596  {
3597  return Empty;
3598  }
3599  if (str0 == null)
3600  {
3601  str0 = Empty;
3602  }
3603  if (str1 == null)
3604  {
3605  str1 = Empty;
3606  }
3607  if (str2 == null)
3608  {
3609  str2 = Empty;
3610  }
3611  if (str3 == null)
3612  {
3613  str3 = Empty;
3614  }
3615  int length = str0.Length + str1.Length + str2.Length + str3.Length;
3616  string text = FastAllocateString(length);
3617  FillStringChecked(text, 0, str0);
3618  FillStringChecked(text, str0.Length, str1);
3619  FillStringChecked(text, str0.Length + str1.Length, str2);
3620  FillStringChecked(text, str0.Length + str1.Length + str2.Length, str3);
3621  return text;
3622  }
3623 
3624  [SecuritySafeCritical]
3625  private static string ConcatArray(string[] values, int totalLength)
3626  {
3627  string text = FastAllocateString(totalLength);
3628  int num = 0;
3629  for (int i = 0; i < values.Length; i++)
3630  {
3631  FillStringChecked(text, num, values[i]);
3632  num += values[i].Length;
3633  }
3634  return text;
3635  }
3636 
3643  [__DynamicallyInvokable]
3644  public static string Concat(params string[] values)
3645  {
3646  if (values == null)
3647  {
3648  throw new ArgumentNullException("values");
3649  }
3650  int num = 0;
3651  string[] array = new string[values.Length];
3652  for (int i = 0; i < values.Length; i++)
3653  {
3654  string text = values[i];
3655  array[i] = ((text == null) ? Empty : text);
3656  num += array[i].Length;
3657  if (num < 0)
3658  {
3659  throw new OutOfMemoryException();
3660  }
3661  }
3662  return ConcatArray(array, num);
3663  }
3664 
3670  [SecuritySafeCritical]
3671  public static string Intern(string str)
3672  {
3673  if (str == null)
3674  {
3675  throw new ArgumentNullException("str");
3676  }
3677  return Thread.GetDomain().GetOrInternString(str);
3678  }
3679 
3685  [SecuritySafeCritical]
3686  public static string IsInterned(string str)
3687  {
3688  if (str == null)
3689  {
3690  throw new ArgumentNullException("str");
3691  }
3692  return Thread.GetDomain().IsStringInterned(str);
3693  }
3694 
3698  {
3699  return TypeCode.String;
3700  }
3701 
3707  [__DynamicallyInvokable]
3708  bool IConvertible.ToBoolean(IFormatProvider provider)
3709  {
3710  return Convert.ToBoolean(this, provider);
3711  }
3712 
3716  [__DynamicallyInvokable]
3717  char IConvertible.ToChar(IFormatProvider provider)
3718  {
3719  return Convert.ToChar(this, provider);
3720  }
3721 
3727  [__DynamicallyInvokable]
3728  sbyte IConvertible.ToSByte(IFormatProvider provider)
3729  {
3730  return Convert.ToSByte(this, provider);
3731  }
3732 
3738  [__DynamicallyInvokable]
3739  byte IConvertible.ToByte(IFormatProvider provider)
3740  {
3741  return Convert.ToByte(this, provider);
3742  }
3743 
3749  [__DynamicallyInvokable]
3750  short IConvertible.ToInt16(IFormatProvider provider)
3751  {
3752  return Convert.ToInt16(this, provider);
3753  }
3754 
3760  [__DynamicallyInvokable]
3761  ushort IConvertible.ToUInt16(IFormatProvider provider)
3762  {
3763  return Convert.ToUInt16(this, provider);
3764  }
3765 
3769  [__DynamicallyInvokable]
3770  int IConvertible.ToInt32(IFormatProvider provider)
3771  {
3772  return Convert.ToInt32(this, provider);
3773  }
3774 
3780  [__DynamicallyInvokable]
3781  uint IConvertible.ToUInt32(IFormatProvider provider)
3782  {
3783  return Convert.ToUInt32(this, provider);
3784  }
3785 
3789  [__DynamicallyInvokable]
3790  long IConvertible.ToInt64(IFormatProvider provider)
3791  {
3792  return Convert.ToInt64(this, provider);
3793  }
3794 
3798  [__DynamicallyInvokable]
3799  ulong IConvertible.ToUInt64(IFormatProvider provider)
3800  {
3801  return Convert.ToUInt64(this, provider);
3802  }
3803 
3807  [__DynamicallyInvokable]
3808  float IConvertible.ToSingle(IFormatProvider provider)
3809  {
3810  return Convert.ToSingle(this, provider);
3811  }
3812 
3818  [__DynamicallyInvokable]
3819  double IConvertible.ToDouble(IFormatProvider provider)
3820  {
3821  return Convert.ToDouble(this, provider);
3822  }
3823 
3829  [__DynamicallyInvokable]
3830  decimal IConvertible.ToDecimal(IFormatProvider provider)
3831  {
3832  return Convert.ToDecimal(this, provider);
3833  }
3834 
3838  [__DynamicallyInvokable]
3839  DateTime IConvertible.ToDateTime(IFormatProvider provider)
3840  {
3841  return Convert.ToDateTime(this, provider);
3842  }
3843 
3851  [__DynamicallyInvokable]
3852  object IConvertible.ToType(Type type, IFormatProvider provider)
3853  {
3854  return Convert.DefaultToType(this, type, provider);
3855  }
3856 
3857  [MethodImpl(MethodImplOptions.InternalCall)]
3858  [SecurityCritical]
3859  internal extern bool IsFastSort();
3860 
3861  [MethodImpl(MethodImplOptions.InternalCall)]
3862  [SecurityCritical]
3863  internal extern bool IsAscii();
3864 
3865  [MethodImpl(MethodImplOptions.InternalCall)]
3866  [SecurityCritical]
3867  internal extern void SetTrailByte(byte data);
3868 
3869  [MethodImpl(MethodImplOptions.InternalCall)]
3870  [SecurityCritical]
3871  internal extern bool TryGetTrailByte(out byte data);
3872 
3876  {
3877  return new CharEnumerator(this);
3878  }
3879 
3882  [__DynamicallyInvokable]
3884  {
3885  return new CharEnumerator(this);
3886  }
3887 
3890  [__DynamicallyInvokable]
3892  {
3893  return new CharEnumerator(this);
3894  }
3895 
3896  [SecurityCritical]
3897  internal unsafe static void InternalCopy(string src, IntPtr dest, int len)
3898  {
3899  if (len != 0)
3900  {
3901  fixed (char* ptr = &src.m_firstChar)
3902  {
3903  byte* src2 = (byte*)ptr;
3904  byte* dest2 = (byte*)(void*)dest;
3905  Buffer.Memcpy(dest2, src2, len);
3906  }
3907  }
3908  }
3909  }
3910 }
Represents a character encoding.To browse the .NET Framework source code for this type,...
Definition: Encoding.cs:15
Converts a base data type to another base data type.
Definition: Convert.cs:10
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
Definition: CultureInfo.cs:263
int CompareTo(object value)
Compares this instance with a specified T:System.Object and indicates whether this instance precedes,...
Definition: String.cs:2107
int LastIndexOf(string value, StringComparison comparisonType)
Reports the zero-based index of the last occurrence of a specified string within the current T:System...
Definition: String.cs:2647
static string Format(string format, object arg0, object arg1)
Replaces the format items in a specified string with the string representation of two specified objec...
Definition: String.cs:3224
string [] Split(params char[] separator)
Splits a string into substrings that are based on the characters in an array.
Definition: String.cs:895
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
The exception that is thrown when there is an attempt to dereference a null object reference.
int LastIndexOf(string value, int startIndex, int count)
Reports the zero-based index position of the last occurrence of a specified string within this instan...
Definition: String.cs:2629
unsafe string GetString(byte *bytes, int byteCount)
When overridden in a derived class, decodes a specified number of bytes starting at a specified addre...
Definition: Encoding.cs:1918
bool EndsWith(string value, bool ignoreCase, CultureInfo culture)
Determines whether the end of this string instance matches the specified string when compared using t...
Definition: String.cs:2283
unsafe String(char *value)
Initializes a new instance of the T:System.String class to the value indicated by a specified pointer...
virtual char [] GetChars(byte[] bytes)
When overridden in a derived class, decodes all the bytes in the specified byte array into a set of c...
Definition: Encoding.cs:1803
bool MoveNext()
Advances the enumerator to the next element of the collection.
Represents text as a sequence of UTF-16 code units.To browse the .NET Framework source code for this ...
Definition: String.cs:18
int LastIndexOf(char value, int startIndex)
Reports the zero-based index position of the last occurrence of a specified Unicode character within ...
Definition: String.cs:2533
static string Concat(params object[] args)
Concatenates the string representations of the elements in a specified T:System.Object array.
Definition: String.cs:3441
int LastIndexOfAny(char[] anyOf)
Reports the zero-based index position of the last occurrence in this instance of one or more characte...
Definition: String.cs:2557
int LastIndexOf(string value)
Reports the zero-based index position of the last occurrence of a specified string within this instan...
Definition: String.cs:2597
virtual byte [] GetBytes(char[] chars)
When overridden in a derived class, encodes all the characters in the specified character array into ...
Definition: Encoding.cs:1576
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
virtual CompareInfo? CompareInfo
Gets the T:System.Globalization.CompareInfo that defines how to compare strings for the culture.
Definition: CultureInfo.cs:447
static string Format(string format, params object[] args)
Replaces the format item in a specified string with the string representation of a corresponding obje...
Definition: String.cs:3254
bool StartsWith(string value, bool ignoreCase, CultureInfo culture)
Determines whether the beginning of this string instance matches the specified string when compared u...
Definition: String.cs:2875
static bool Equals(string a, string b)
Determines whether two specified T:System.String objects have the same value.
Definition: String.cs:585
int LastIndexOf(char value)
Reports the zero-based index position of the last occurrence of a specified Unicode character within ...
Definition: String.cs:2521
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
bool ToBoolean(IFormatProvider provider)
Converts the value of this instance to an equivalent Boolean value using the specified culture-specif...
TypeCode
Specifies the type of an object.
Definition: TypeCode.cs:9
string ToUpper()
Returns a copy of this string converted to uppercase.
Definition: String.cs:2922
int GetRemainingCount()
Returns the number of arguments remaining in the argument list.
static sbyte Min(sbyte val1, sbyte val2)
Returns the smaller of two 8-bit signed integers.
Definition: Math.cs:762
CharEnumerator GetEnumerator()
Retrieves an object that can iterate through the individual characters in this string.
Definition: String.cs:3875
Definition: __Canon.cs:3
int CompareTo(string strB)
Compares this instance with a specified T:System.String object and indicates whether this instance pr...
Definition: String.cs:2125
string [] Split(char[] separator, int count)
Splits a string into a maximum number of substrings based on the characters in an array....
Definition: String.cs:907
The exception that is thrown when the value of an argument is outside the allowable range of values a...
string [] Split(char[] separator, int count, StringSplitOptions options)
Splits a string into a maximum number of substrings based on the characters in an array.
Definition: String.cs:938
string [] Split(string[] separator, int count, StringSplitOptions options)
Splits a string into a maximum number of substrings based on the strings in an array....
Definition: String.cs:1001
int IndexOf(char value, int startIndex)
Reports the zero-based index of the first occurrence of the specified Unicode character in this strin...
Definition: String.cs:2323
string Substring(int startIndex)
Retrieves a substring from this instance. The substring starts at a specified character position and ...
Definition: String.cs:1200
string Substring(int startIndex, int length)
Retrieves a substring from this instance. The substring starts at a specified character position and ...
Definition: String.cs:1214
bool StartsWith(string value, StringComparison comparisonType)
Determines whether the beginning of this string instance matches the specified string when compared u...
Definition: String.cs:2821
unsafe TypedReference GetNextArg()
Returns the next argument in a variable-length argument list.
Definition: ArgIterator.cs:50
string TrimStart(params char[] trimChars)
Removes all leading occurrences of a set of characters specified in an array from the current T:Syste...
Definition: String.cs:1274
Provides a mechanism for retrieving an object to control formatting.
static bool IsNullOrWhiteSpace(string value)
Indicates whether a specified string is null, empty, or consists only of white-space characters.
Definition: String.cs:803
virtual int GetCharCount(byte[] bytes)
When overridden in a derived class, calculates the number of characters produced by decoding all the ...
Definition: Encoding.cs:1734
static int Compare(string strA, int indexA, string strB, int indexB, int length, bool ignoreCase)
Compares substrings of two specified T:System.String objects, ignoring or honoring their case,...
Definition: String.cs:1920
bool EndsWith(string value, StringComparison comparisonType)
Determines whether the end of this string instance matches the specified string when compared using t...
Definition: String.cs:2229
string Remove(int startIndex)
Returns a new string in which all the characters in the current instance, beginning at a specified po...
Definition: String.cs:3188
static int Compare(string strA, int indexA, string strB, int indexB, int length)
Compares substrings of two specified T:System.String objects and returns an integer that indicates th...
Definition: String.cs:1892
string ToLower()
Returns a copy of this string converted to lowercase.
Definition: String.cs:2892
static string Intern(string str)
Retrieves the system's reference to the specified T:System.String.
Definition: String.cs:3671
int LastIndexOf(string value, int startIndex, StringComparison comparisonType)
Reports the zero-based index of the last occurrence of a specified string within the current T:System...
Definition: String.cs:2664
static unsafe string Copy(string str)
Creates a new instance of T:System.String with the same value as a specified T:System....
Definition: String.cs:3345
TypeCode GetTypeCode()
Returns the T:System.TypeCode for class T:System.String.
Definition: String.cs:3697
virtual int LastIndexOf(string source, char value)
Searches for the specified character and returns the zero-based index of the last occurrence within t...
Definition: CompareInfo.cs:915
int LastIndexOfAny(char[] anyOf, int startIndex)
Reports the zero-based index position of the last occurrence in this instance of one or more characte...
Definition: String.cs:2571
static string Concat(IEnumerable< string > values)
Concatenates the members of a constructed T:System.Collections.Generic.IEnumerable`1 collection of ty...
Definition: String.cs:3505
virtual TextInfo TextInfo
Gets the T:System.Globalization.TextInfo that defines the writing system associated with the culture.
Definition: CultureInfo.cs:480
virtual bool IsSuffix(string source, string suffix, CompareOptions options)
Determines whether the specified source string ends with the specified suffix using the specified T:S...
Definition: CompareInfo.cs:577
Defines a generalized type-specific comparison method that a value type or class implements to order ...
Definition: IComparable.cs:8
Supports iterating over a T:System.String object and reading its individual characters....
A type representing a date and time value.
static int CompareOrdinal(string strA, int indexA, string strB, int indexB, int length)
Compares substrings of two specified T:System.String objects by evaluating the numeric values of the ...
Definition: String.cs:2176
Cer
Specifies a method's behavior when called within a constrained execution region.
Definition: Cer.cs:5
static string Format(string format, object arg0, object arg1, object arg2)
Replaces the format items in a specified string with the string representation of three specified obj...
Definition: String.cs:3240
int IndexOf(char value)
Reports the zero-based index of the first occurrence of the specified Unicode character in this strin...
Definition: String.cs:2311
Represents a variable-length argument list; that is, the parameters of a function that takes a variab...
Definition: ArgIterator.cs:7
static unsafe object ToObject(TypedReference value)
Converts the specified TypedReference to an Object.
static string Join(string separator, params object[] values)
Concatenates the elements of an object array, using the specified separator between each element.
Definition: String.cs:92
string ToLowerInvariant()
Returns a copy of this T:System.String object converted to lowercase using the casing rules of the in...
Definition: String.cs:2914
string [] Split(char[] separator, StringSplitOptions options)
Splits a string into substrings based on the characters in an array. You can specify whether the subs...
Definition: String.cs:921
static string Format(IFormatProvider provider, string format, object arg0, object arg1, object arg2)
Replaces the format items in a specified string with the string representation of three specified obj...
Definition: String.cs:3306
Exposes an enumerator, which supports a simple iteration over a non-generic collection....
Definition: IEnumerable.cs:9
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
static bool ToBoolean(object value)
Converts the value of a specified object to an equivalent Boolean value.
Definition: Convert.cs:457
Describes objects that contain both a managed pointer to a location and a runtime representation of t...
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
static int Compare(string strA, int indexA, string strB, int indexB, int length, bool ignoreCase, CultureInfo culture)
Compares substrings of two specified T:System.String objects, ignoring or honoring their case and usi...
Definition: String.cs:1955
static string Format(IFormatProvider provider, string format, object arg0, object arg1)
Replaces the format items in a specified string with the string representation of two specified objec...
Definition: String.cs:3289
A cast or conversion operation, such as (SampleType)obj in C::or CType(obj, SampleType) in Visual Bas...
The exception that is thrown when an attempt is made to access an element of an array or collection w...
static readonly string Empty
Represents the empty string. This field is read-only.
Definition: String.cs:34
static unsafe string Join(string separator, string[] value, int startIndex, int count)
Concatenates the specified elements of a string array, using the specified separator between each ele...
Definition: String.cs:233
NormalizationForm
Defines the type of normalization to perform.
string ToString(IFormatProvider provider)
Returns this instance of T:System.String; no actual conversion is performed.
Definition: String.cs:2960
static bool operator !=(string a, string b)
Determines whether two specified strings have different values.
Definition: String.cs:674
StringSplitOptions
Specifies whether applicable Overload:System.String.Split method overloads include or omit empty subs...
static string Join(string separator, params string[] value)
Concatenates all the elements of a string array, using the specified separator between each element.
Definition: String.cs:75
virtual int Compare(string string1, string string2)
Compares two strings.
Definition: CompareInfo.cs:313
bool Equals(string value)
Determines whether this instance and another specified T:System.String object have the same value.
Definition: String.cs:504
string Trim(params char[] trimChars)
Removes all leading and trailing occurrences of a set of characters specified in an array from the cu...
Definition: String.cs:1261
object Clone()
Returns a reference to this instance of T:System.String.
Definition: String.cs:2967
bool IsNormalized(NormalizationForm normalizationForm)
Indicates whether this string is in the specified Unicode normalization form.
Definition: String.cs:1454
static string Concat(object arg0, object arg1)
Concatenates the string representations of two specified objects.
Definition: String.cs:3381
static string Format(string format, object arg0)
Replaces one or more format items in a specified string with the string representation of a specified...
Definition: String.cs:3209
unsafe char [] ToCharArray()
Copies the characters in this instance to a Unicode character array.
Definition: String.cs:732
string ToUpperInvariant()
Returns a copy of this T:System.String object converted to uppercase using the casing rules of the in...
Definition: String.cs:2944
static string Concat(object arg0)
Creates the string representation of a specified object.
Definition: String.cs:3367
string PadRight(int totalWidth, char paddingChar)
Returns a new string that left-aligns the characters in this string by padding them on the right with...
Definition: String.cs:2784
object Current
Gets the element in the collection at the current position of the enumerator.
Definition: IEnumerator.cs:15
unsafe override int GetHashCode()
Returns the hash code for this string.
Definition: String.cs:839
string Replace(string oldValue, string newValue)
Returns a new string in which all occurrences of a specified string in the current instance are repla...
Definition: String.cs:3131
int IndexOf(string value, int startIndex)
Reports the zero-based index of the first occurrence of the specified string in this instance....
Definition: String.cs:2403
static string Format(IFormatProvider provider, string format, object arg0)
Replaces the format item or items in a specified string with the string representation of the corresp...
Definition: String.cs:3273
virtual char ToLower(char c)
Converts the specified character to lowercase.
Definition: TextInfo.cs:362
string TrimEnd(params char[] trimChars)
Removes all trailing occurrences of a set of characters specified in an array from the current T:Syst...
Definition: String.cs:1287
Supports cloning, which creates a new instance of a class with the same value as an existing instance...
Definition: ICloneable.cs:7
static int Compare(string strA, int indexA, string strB, int indexB, int length, StringComparison comparisonType)
Compares substrings of two specified T:System.String objects using the specified rules,...
Definition: String.cs:2030
static string Concat(params string[] values)
Concatenates the elements of a specified T:System.String array.
Definition: String.cs:3644
static string Concat(object arg0, object arg1, object arg2)
Concatenates the string representations of three specified objects.
Definition: String.cs:3400
string PadRight(int totalWidth)
Returns a new string that left-aligns the characters in this string by padding them with spaces on th...
Definition: String.cs:2772
int IndexOf(string value)
Reports the zero-based index of the first occurrence of the specified string in this instance.
Definition: String.cs:2389
The exception that is thrown when there is not enough memory to continue the execution of a program.
static string Concat(string str0, string str1)
Concatenates two specified instances of T:System.String.
Definition: String.cs:3531
static bool Equals(string a, string b, StringComparison comparisonType)
Determines whether two specified T:System.String objects have the same value. A parameter specifies t...
Definition: String.cs:612
new T Current
Gets the element in the collection at the current position of the enumerator.
Definition: IEnumerator.cs:12
static int Compare(string strA, string strB, bool ignoreCase)
Compares two specified T:System.String objects, ignoring or honoring their case, and returns an integ...
Definition: String.cs:1764
string Replace(char oldChar, char newChar)
Returns a new string in which all occurrences of a specified Unicode character in this instance are r...
Definition: String.cs:3113
int IndexOfAny(char[] anyOf)
Reports the zero-based index of the first occurrence in this instance of any character in a specified...
Definition: String.cs:2348
MethodImplOptions
Defines the details of how a method is implemented.
static AppDomain GetDomain()
Returns the current domain in which the current thread is running.
Definition: Thread.cs:1096
CharSet
Dictates which character set marshaled strings should use.
Definition: CharSet.cs:7
unsafe char [] ToCharArray(int startIndex, int length)
Copies the characters in a specified substring in this instance to a Unicode character array.
Definition: String.cs:759
bool Contains(string value)
Returns a value indicating whether a specified substring occurs within this string.
Definition: String.cs:2200
IEnumerator GetEnumerator()
Returns an enumerator that iterates through a collection.
bool StartsWith(string value)
Determines whether the beginning of this string instance matches the specified string.
Definition: String.cs:2800
string ToUpper(CultureInfo culture)
Returns a copy of this string converted to uppercase, using the casing rules of the specified culture...
Definition: String.cs:2932
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
int IndexOf(string value, int startIndex, StringComparison comparisonType)
Reports the zero-based index of the first occurrence of the specified string in the current T:System....
Definition: String.cs:2459
static string IsInterned(string str)
Retrieves a reference to a specified T:System.String.
Definition: String.cs:3686
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
Definition: CultureInfo.cs:120
string PadLeft(int totalWidth)
Returns a new string that right-aligns the characters in this instance by padding them with spaces on...
Definition: String.cs:2749
The exception that is thrown when one of the arguments provided to a method is not valid.
bool IsNormalized()
Indicates whether this string is in Unicode normalization form C.
Definition: String.cs:1443
unsafe string Remove(int startIndex, int count)
Returns a new string in which a specified number of characters in the current instance beginning at a...
Definition: String.cs:3149
static string Format(IFormatProvider provider, string format, params object[] args)
Replaces the format items in a specified string with the string representations of corresponding obje...
Definition: String.cs:3321
virtual int IndexOf(string source, char value)
Searches for the specified character and returns the zero-based index of the first occurrence within ...
Definition: CompareInfo.cs:623
static bool IsNullOrEmpty(string value)
Indicates whether the specified string is null or an F:System.String.Empty string.
Definition: String.cs:789
override string ToString()
Returns this instance of T:System.String; no actual conversion is performed.
Definition: String.cs:2952
static int Compare(string strA, string strB)
Compares two specified T:System.String objects and returns an integer that indicates their relative p...
Definition: String.cs:1749
int IndexOfAny(char[] anyOf, int startIndex)
Reports the zero-based index of the first occurrence in this instance of any character in a specified...
Definition: String.cs:2363
virtual bool IsPrefix(string source, string prefix, CompareOptions options)
Determines whether the specified source string starts with the specified prefix using the specified T...
Definition: CompareInfo.cs:525
bool EndsWith(string value)
Determines whether the end of this string instance matches the specified string.
Definition: String.cs:2212
static string Join(string separator, IEnumerable< string > values)
Concatenates the members of a constructed T:System.Collections.Generic.IEnumerable`1 collection of ty...
Definition: String.cs:185
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition: IEquatable.cs:6
Specifies that the class can be serialized.
int IndexOf(string value, int startIndex, int count, StringComparison comparisonType)
Reports the zero-based index of the first occurrence of the specified string in the current T:System....
Definition: String.cs:2480
static bool operator==(string a, string b)
Determines whether two specified strings have the same value.
Definition: String.cs:663
string Normalize()
Returns a new string whose textual value is the same as this string, but whose binary representation ...
Definition: String.cs:1466
bool Equals(string value, StringComparison comparisonType)
Determines whether this string and a specified T:System.String object have the same value....
Definition: String.cs:534
Consistency
Specifies a reliability contract.
Definition: Consistency.cs:5
Defines text properties and behaviors, such as casing, that are specific to a writing system.
Definition: TextInfo.cs:13
static int CompareOrdinal(string strA, string strB)
Compares two specified T:System.String objects by evaluating the numeric values of the corresponding ...
Definition: String.cs:2142
static string Join< T >(string separator, IEnumerable< T > values)
Concatenates the members of a collection, using the specified separator between each member.
Definition: String.cs:136
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
Provides constants and static methods for trigonometric, logarithmic, and other common mathematical f...
Definition: Math.cs:10
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...
CompareOptions
Defines the string comparison options to use with T:System.Globalization.CompareInfo.
static string Concat< T >(IEnumerable< T > values)
Concatenates the members of an T:System.Collections.Generic.IEnumerable`1 implementation.
Definition: String.cs:3474
virtual char ToUpper(char c)
Converts the specified character to uppercase.
Definition: TextInfo.cs:401
Defines methods that convert the value of the implementing reference or value type to a common langua...
Definition: IConvertible.cs:9
int IndexOf(string value, StringComparison comparisonType)
Reports the zero-based index of the first occurrence of the specified string in the current T:System....
Definition: String.cs:2442
int Length
Gets the number of characters in the current T:System.String object.
Definition: String.cs:61
static string Concat(string str0, string str1, string str2)
Concatenates three specified instances of T:System.String.
Definition: String.cs:3559
override bool Equals(object obj)
Determines whether this instance and a specified object, which must also be a T:System....
Definition: String.cs:476
static int Compare(string strA, int indexA, string strB, int indexB, int length, CultureInfo culture, CompareOptions options)
Compares substrings of two specified T:System.String objects using the specified comparison options a...
Definition: String.cs:1995
static int Compare(string strA, string strB, CultureInfo culture, CompareOptions options)
Compares two specified T:System.String objects using the specified comparison options and culture-spe...
Definition: String.cs:1846
string [] Split(string[] separator, StringSplitOptions options)
Splits a string into substrings based on the strings in an array. You can specify whether the substri...
Definition: String.cs:984
static string Concat(string str0, string str1, string str2, string str3)
Concatenates four specified instances of T:System.String.
Definition: String.cs:3593
unsafe 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...
Definition: String.cs:694
static int Compare(string strA, string strB, bool ignoreCase, CultureInfo culture)
Compares two specified T:System.String objects, ignoring or honoring their case, and using culture-sp...
Definition: String.cs:1867
int LastIndexOf(string value, int startIndex, int count, StringComparison comparisonType)
Reports the zero-based index position of the last occurrence of a specified string within this instan...
Definition: String.cs:2686
string Normalize(NormalizationForm normalizationForm)
Returns a new string whose textual value is the same as this string, but whose binary representation ...
Definition: String.cs:1476
int LastIndexOf(string value, int startIndex)
Reports the zero-based index position of the last occurrence of a specified string within this instan...
Definition: String.cs:2611
unsafe string Insert(int startIndex, string value)
Returns a new string in which a specified string is inserted at a specified index position in this in...
Definition: String.cs:3071
int IndexOf(string value, int startIndex, int count)
Reports the zero-based index of the first occurrence of the specified string in this instance....
Definition: String.cs:2420
string PadLeft(int totalWidth, char paddingChar)
Returns a new string that right-aligns the characters in this instance by padding them on the left wi...
Definition: String.cs:2761
string Trim()
Removes all leading and trailing white-space characters from the current T:System....
Definition: String.cs:2980
static int Compare(string strA, string strB, StringComparison comparisonType)
Compares two specified T:System.String objects using the specified rules, and returns an integer that...
Definition: String.cs:1787
string ToLower(CultureInfo culture)
Returns a copy of this string converted to lowercase, using the casing rules of the specified culture...
Definition: String.cs:2902
Creates and controls a thread, sets its priority, and gets its status.
Definition: Thread.cs:18