mscorlib(4.0.0.0) API with additions
Char.cs
4 
5 namespace System
6 {
9  [ComVisible(true)]
10  [__DynamicallyInvokable]
11  public struct Char : IComparable, IConvertible, IComparable<char>, IEquatable<char>
12  {
13  internal char m_value;
14 
16  [__DynamicallyInvokable]
17  public const char MaxValue = '\uffff';
18 
20  [__DynamicallyInvokable]
21  public const char MinValue = '\0';
22 
23  private static readonly byte[] categoryForLatin1 = new byte[256]
24  {
25  14,
26  14,
27  14,
28  14,
29  14,
30  14,
31  14,
32  14,
33  14,
34  14,
35  14,
36  14,
37  14,
38  14,
39  14,
40  14,
41  14,
42  14,
43  14,
44  14,
45  14,
46  14,
47  14,
48  14,
49  14,
50  14,
51  14,
52  14,
53  14,
54  14,
55  14,
56  14,
57  11,
58  24,
59  24,
60  24,
61  26,
62  24,
63  24,
64  24,
65  20,
66  21,
67  24,
68  25,
69  24,
70  19,
71  24,
72  24,
73  8,
74  8,
75  8,
76  8,
77  8,
78  8,
79  8,
80  8,
81  8,
82  8,
83  24,
84  24,
85  25,
86  25,
87  25,
88  24,
89  24,
90  0,
91  0,
92  0,
93  0,
94  0,
95  0,
96  0,
97  0,
98  0,
99  0,
100  0,
101  0,
102  0,
103  0,
104  0,
105  0,
106  0,
107  0,
108  0,
109  0,
110  0,
111  0,
112  0,
113  0,
114  0,
115  0,
116  20,
117  24,
118  21,
119  27,
120  18,
121  27,
122  1,
123  1,
124  1,
125  1,
126  1,
127  1,
128  1,
129  1,
130  1,
131  1,
132  1,
133  1,
134  1,
135  1,
136  1,
137  1,
138  1,
139  1,
140  1,
141  1,
142  1,
143  1,
144  1,
145  1,
146  1,
147  1,
148  20,
149  25,
150  21,
151  25,
152  14,
153  14,
154  14,
155  14,
156  14,
157  14,
158  14,
159  14,
160  14,
161  14,
162  14,
163  14,
164  14,
165  14,
166  14,
167  14,
168  14,
169  14,
170  14,
171  14,
172  14,
173  14,
174  14,
175  14,
176  14,
177  14,
178  14,
179  14,
180  14,
181  14,
182  14,
183  14,
184  14,
185  11,
186  24,
187  26,
188  26,
189  26,
190  26,
191  28,
192  28,
193  27,
194  28,
195  1,
196  22,
197  25,
198  19,
199  28,
200  27,
201  28,
202  25,
203  10,
204  10,
205  27,
206  1,
207  28,
208  24,
209  27,
210  10,
211  1,
212  23,
213  10,
214  10,
215  10,
216  24,
217  0,
218  0,
219  0,
220  0,
221  0,
222  0,
223  0,
224  0,
225  0,
226  0,
227  0,
228  0,
229  0,
230  0,
231  0,
232  0,
233  0,
234  0,
235  0,
236  0,
237  0,
238  0,
239  0,
240  25,
241  0,
242  0,
243  0,
244  0,
245  0,
246  0,
247  0,
248  1,
249  1,
250  1,
251  1,
252  1,
253  1,
254  1,
255  1,
256  1,
257  1,
258  1,
259  1,
260  1,
261  1,
262  1,
263  1,
264  1,
265  1,
266  1,
267  1,
268  1,
269  1,
270  1,
271  1,
272  25,
273  1,
274  1,
275  1,
276  1,
277  1,
278  1,
279  1,
280  1
281  };
282 
283  internal const int UNICODE_PLANE00_END = 65535;
284 
285  internal const int UNICODE_PLANE01_START = 65536;
286 
287  internal const int UNICODE_PLANE16_END = 1114111;
288 
289  internal const int HIGH_SURROGATE_START = 55296;
290 
291  internal const int LOW_SURROGATE_END = 57343;
292 
293  private static bool IsLatin1(char ch)
294  {
295  return ch <= 'ΓΏ';
296  }
297 
298  private static bool IsAscii(char ch)
299  {
300  return ch <= '\u007f';
301  }
302 
303  private static UnicodeCategory GetLatin1UnicodeCategory(char ch)
304  {
305  return (UnicodeCategory)categoryForLatin1[ch];
306  }
307 
310  [__DynamicallyInvokable]
311  public override int GetHashCode()
312  {
313  return (int)(this | ((uint)this << 16));
314  }
315 
320  [__DynamicallyInvokable]
321  public override bool Equals(object obj)
322  {
323  if (!(obj is char))
324  {
325  return false;
326  }
327  return this == (char)obj;
328  }
329 
334  [NonVersionable]
335  [__DynamicallyInvokable]
336  public bool Equals(char obj)
337  {
338  return this == obj;
339  }
340 
347  public int CompareTo(object value)
348  {
349  if (value == null)
350  {
351  return 1;
352  }
353  if (!(value is char))
354  {
355  throw new ArgumentException(Environment.GetResourceString("Arg_MustBeChar"));
356  }
357  return this - (char)value;
358  }
359 
363  [__DynamicallyInvokable]
364  public int CompareTo(char value)
365  {
366  return this - value;
367  }
368 
371  [__DynamicallyInvokable]
372  public override string ToString()
373  {
374  return ToString(this);
375  }
376 
380  public string ToString(IFormatProvider provider)
381  {
382  return ToString(this);
383  }
384 
388  [__DynamicallyInvokable]
389  public static string ToString(char c)
390  {
391  return new string(c, 1);
392  }
393 
400  [__DynamicallyInvokable]
401  public static char Parse(string s)
402  {
403  if (s == null)
404  {
405  throw new ArgumentNullException("s");
406  }
407  if (s.Length != 1)
408  {
409  throw new FormatException(Environment.GetResourceString("Format_NeedSingleChar"));
410  }
411  return s[0];
412  }
413 
419  [__DynamicallyInvokable]
420  public static bool TryParse(string s, out char result)
421  {
422  result = '\0';
423  if (s == null)
424  {
425  return false;
426  }
427  if (s.Length != 1)
428  {
429  return false;
430  }
431  result = s[0];
432  return true;
433  }
434 
439  [__DynamicallyInvokable]
440  public static bool IsDigit(char c)
441  {
442  if (IsLatin1(c))
443  {
444  if (c >= '0')
445  {
446  return c <= '9';
447  }
448  return false;
449  }
450  return CharUnicodeInfo.GetUnicodeCategory(c) == UnicodeCategory.DecimalDigitNumber;
451  }
452 
453  internal static bool CheckLetter(UnicodeCategory uc)
454  {
455  switch (uc)
456  {
457  case UnicodeCategory.UppercaseLetter:
458  case UnicodeCategory.LowercaseLetter:
459  case UnicodeCategory.TitlecaseLetter:
460  case UnicodeCategory.ModifierLetter:
461  case UnicodeCategory.OtherLetter:
462  return true;
463  default:
464  return false;
465  }
466  }
467 
472  [__DynamicallyInvokable]
473  public static bool IsLetter(char c)
474  {
475  if (IsLatin1(c))
476  {
477  if (IsAscii(c))
478  {
479  c = (char)(c | 0x20);
480  if (c >= 'a')
481  {
482  return c <= 'z';
483  }
484  return false;
485  }
486  return CheckLetter(GetLatin1UnicodeCategory(c));
487  }
488  return CheckLetter(CharUnicodeInfo.GetUnicodeCategory(c));
489  }
490 
491  private static bool IsWhiteSpaceLatin1(char c)
492  {
493  switch (c)
494  {
495  default:
496  if (c != '\u00a0' && c != '\u0085')
497  {
498  return false;
499  }
500  goto case '\t';
501  case '\t':
502  case '\n':
503  case '\v':
504  case '\f':
505  case '\r':
506  case ' ':
507  return true;
508  }
509  }
510 
515  [__DynamicallyInvokable]
516  public static bool IsWhiteSpace(char c)
517  {
518  if (IsLatin1(c))
519  {
520  return IsWhiteSpaceLatin1(c);
521  }
522  return CharUnicodeInfo.IsWhiteSpace(c);
523  }
524 
529  [__DynamicallyInvokable]
530  public static bool IsUpper(char c)
531  {
532  if (IsLatin1(c))
533  {
534  if (IsAscii(c))
535  {
536  if (c >= 'A')
537  {
538  return c <= 'Z';
539  }
540  return false;
541  }
542  return GetLatin1UnicodeCategory(c) == UnicodeCategory.UppercaseLetter;
543  }
544  return CharUnicodeInfo.GetUnicodeCategory(c) == UnicodeCategory.UppercaseLetter;
545  }
546 
551  [__DynamicallyInvokable]
552  public static bool IsLower(char c)
553  {
554  if (IsLatin1(c))
555  {
556  if (IsAscii(c))
557  {
558  if (c >= 'a')
559  {
560  return c <= 'z';
561  }
562  return false;
563  }
564  return GetLatin1UnicodeCategory(c) == UnicodeCategory.LowercaseLetter;
565  }
566  return CharUnicodeInfo.GetUnicodeCategory(c) == UnicodeCategory.LowercaseLetter;
567  }
568 
569  internal static bool CheckPunctuation(UnicodeCategory uc)
570  {
571  switch (uc)
572  {
573  case UnicodeCategory.ConnectorPunctuation:
574  case UnicodeCategory.DashPunctuation:
575  case UnicodeCategory.OpenPunctuation:
576  case UnicodeCategory.ClosePunctuation:
577  case UnicodeCategory.InitialQuotePunctuation:
578  case UnicodeCategory.FinalQuotePunctuation:
579  case UnicodeCategory.OtherPunctuation:
580  return true;
581  default:
582  return false;
583  }
584  }
585 
590  [__DynamicallyInvokable]
591  public static bool IsPunctuation(char c)
592  {
593  if (IsLatin1(c))
594  {
595  return CheckPunctuation(GetLatin1UnicodeCategory(c));
596  }
597  return CheckPunctuation(CharUnicodeInfo.GetUnicodeCategory(c));
598  }
599 
600  internal static bool CheckLetterOrDigit(UnicodeCategory uc)
601  {
602  switch (uc)
603  {
604  case UnicodeCategory.UppercaseLetter:
605  case UnicodeCategory.LowercaseLetter:
606  case UnicodeCategory.TitlecaseLetter:
607  case UnicodeCategory.ModifierLetter:
608  case UnicodeCategory.OtherLetter:
609  case UnicodeCategory.DecimalDigitNumber:
610  return true;
611  default:
612  return false;
613  }
614  }
615 
620  [__DynamicallyInvokable]
621  public static bool IsLetterOrDigit(char c)
622  {
623  if (IsLatin1(c))
624  {
625  return CheckLetterOrDigit(GetLatin1UnicodeCategory(c));
626  }
627  return CheckLetterOrDigit(CharUnicodeInfo.GetUnicodeCategory(c));
628  }
629 
637  [__DynamicallyInvokable]
638  public static char ToUpper(char c, CultureInfo culture)
639  {
640  if (culture == null)
641  {
642  throw new ArgumentNullException("culture");
643  }
644  return culture.TextInfo.ToUpper(c);
645  }
646 
650  [__DynamicallyInvokable]
651  public static char ToUpper(char c)
652  {
654  }
655 
659  [__DynamicallyInvokable]
660  public static char ToUpperInvariant(char c)
661  {
663  }
664 
672  [__DynamicallyInvokable]
673  public static char ToLower(char c, CultureInfo culture)
674  {
675  if (culture == null)
676  {
677  throw new ArgumentNullException("culture");
678  }
679  return culture.TextInfo.ToLower(c);
680  }
681 
685  [__DynamicallyInvokable]
686  public static char ToLower(char c)
687  {
689  }
690 
694  [__DynamicallyInvokable]
695  public static char ToLowerInvariant(char c)
696  {
698  }
699 
703  {
704  return TypeCode.Char;
705  }
706 
712  [__DynamicallyInvokable]
714  {
715  throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", "Char", "Boolean"));
716  }
717 
721  [__DynamicallyInvokable]
723  {
724  return this;
725  }
726 
730  [__DynamicallyInvokable]
732  {
733  return Convert.ToSByte(this);
734  }
735 
739  [__DynamicallyInvokable]
741  {
742  return Convert.ToByte(this);
743  }
744 
748  [__DynamicallyInvokable]
750  {
751  return Convert.ToInt16(this);
752  }
753 
757  [__DynamicallyInvokable]
759  {
760  return Convert.ToUInt16(this);
761  }
762 
766  [__DynamicallyInvokable]
768  {
769  return Convert.ToInt32(this);
770  }
771 
775  [__DynamicallyInvokable]
777  {
778  return Convert.ToUInt32(this);
779  }
780 
784  [__DynamicallyInvokable]
786  {
787  return Convert.ToInt64(this);
788  }
789 
793  [__DynamicallyInvokable]
795  {
796  return Convert.ToUInt64(this);
797  }
798 
804  [__DynamicallyInvokable]
806  {
807  throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", "Char", "Single"));
808  }
809 
815  [__DynamicallyInvokable]
817  {
818  throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", "Char", "Double"));
819  }
820 
826  [__DynamicallyInvokable]
828  {
829  throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", "Char", "Decimal"));
830  }
831 
837  [__DynamicallyInvokable]
839  {
840  throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", "Char", "DateTime"));
841  }
842 
850  [__DynamicallyInvokable]
851  object IConvertible.ToType(Type type, IFormatProvider provider)
852  {
853  return Convert.DefaultToType(this, type, provider);
854  }
855 
860  [__DynamicallyInvokable]
861  public static bool IsControl(char c)
862  {
863  if (IsLatin1(c))
864  {
865  return GetLatin1UnicodeCategory(c) == UnicodeCategory.Control;
866  }
868  }
869 
879  [__DynamicallyInvokable]
880  public static bool IsControl(string s, int index)
881  {
882  if (s == null)
883  {
884  throw new ArgumentNullException("s");
885  }
886  if ((uint)index >= (uint)s.Length)
887  {
888  throw new ArgumentOutOfRangeException("index");
889  }
890  char ch = s[index];
891  if (IsLatin1(ch))
892  {
893  return GetLatin1UnicodeCategory(ch) == UnicodeCategory.Control;
894  }
895  return CharUnicodeInfo.GetUnicodeCategory(s, index) == UnicodeCategory.Control;
896  }
897 
907  [__DynamicallyInvokable]
908  public static bool IsDigit(string s, int index)
909  {
910  if (s == null)
911  {
912  throw new ArgumentNullException("s");
913  }
914  if ((uint)index >= (uint)s.Length)
915  {
916  throw new ArgumentOutOfRangeException("index");
917  }
918  char c = s[index];
919  if (IsLatin1(c))
920  {
921  if (c >= '0')
922  {
923  return c <= '9';
924  }
925  return false;
926  }
927  return CharUnicodeInfo.GetUnicodeCategory(s, index) == UnicodeCategory.DecimalDigitNumber;
928  }
929 
939  [__DynamicallyInvokable]
940  public static bool IsLetter(string s, int index)
941  {
942  if (s == null)
943  {
944  throw new ArgumentNullException("s");
945  }
946  if ((uint)index >= (uint)s.Length)
947  {
948  throw new ArgumentOutOfRangeException("index");
949  }
950  char c = s[index];
951  if (IsLatin1(c))
952  {
953  if (IsAscii(c))
954  {
955  c = (char)(c | 0x20);
956  if (c >= 'a')
957  {
958  return c <= 'z';
959  }
960  return false;
961  }
962  return CheckLetter(GetLatin1UnicodeCategory(c));
963  }
964  return CheckLetter(CharUnicodeInfo.GetUnicodeCategory(s, index));
965  }
966 
976  [__DynamicallyInvokable]
977  public static bool IsLetterOrDigit(string s, int index)
978  {
979  if (s == null)
980  {
981  throw new ArgumentNullException("s");
982  }
983  if ((uint)index >= (uint)s.Length)
984  {
985  throw new ArgumentOutOfRangeException("index");
986  }
987  char ch = s[index];
988  if (IsLatin1(ch))
989  {
990  return CheckLetterOrDigit(GetLatin1UnicodeCategory(ch));
991  }
992  return CheckLetterOrDigit(CharUnicodeInfo.GetUnicodeCategory(s, index));
993  }
994 
1004  [__DynamicallyInvokable]
1005  public static bool IsLower(string s, int index)
1006  {
1007  if (s == null)
1008  {
1009  throw new ArgumentNullException("s");
1010  }
1011  if ((uint)index >= (uint)s.Length)
1012  {
1013  throw new ArgumentOutOfRangeException("index");
1014  }
1015  char c = s[index];
1016  if (IsLatin1(c))
1017  {
1018  if (IsAscii(c))
1019  {
1020  if (c >= 'a')
1021  {
1022  return c <= 'z';
1023  }
1024  return false;
1025  }
1026  return GetLatin1UnicodeCategory(c) == UnicodeCategory.LowercaseLetter;
1027  }
1028  return CharUnicodeInfo.GetUnicodeCategory(s, index) == UnicodeCategory.LowercaseLetter;
1029  }
1030 
1031  internal static bool CheckNumber(UnicodeCategory uc)
1032  {
1033  switch (uc)
1034  {
1035  case UnicodeCategory.DecimalDigitNumber:
1036  case UnicodeCategory.LetterNumber:
1037  case UnicodeCategory.OtherNumber:
1038  return true;
1039  default:
1040  return false;
1041  }
1042  }
1043 
1048  [__DynamicallyInvokable]
1049  public static bool IsNumber(char c)
1050  {
1051  if (IsLatin1(c))
1052  {
1053  if (IsAscii(c))
1054  {
1055  if (c >= '0')
1056  {
1057  return c <= '9';
1058  }
1059  return false;
1060  }
1061  return CheckNumber(GetLatin1UnicodeCategory(c));
1062  }
1063  return CheckNumber(CharUnicodeInfo.GetUnicodeCategory(c));
1064  }
1065 
1075  [__DynamicallyInvokable]
1076  public static bool IsNumber(string s, int index)
1077  {
1078  if (s == null)
1079  {
1080  throw new ArgumentNullException("s");
1081  }
1082  if ((uint)index >= (uint)s.Length)
1083  {
1084  throw new ArgumentOutOfRangeException("index");
1085  }
1086  char c = s[index];
1087  if (IsLatin1(c))
1088  {
1089  if (IsAscii(c))
1090  {
1091  if (c >= '0')
1092  {
1093  return c <= '9';
1094  }
1095  return false;
1096  }
1097  return CheckNumber(GetLatin1UnicodeCategory(c));
1098  }
1099  return CheckNumber(CharUnicodeInfo.GetUnicodeCategory(s, index));
1100  }
1101 
1111  [__DynamicallyInvokable]
1112  public static bool IsPunctuation(string s, int index)
1113  {
1114  if (s == null)
1115  {
1116  throw new ArgumentNullException("s");
1117  }
1118  if ((uint)index >= (uint)s.Length)
1119  {
1120  throw new ArgumentOutOfRangeException("index");
1121  }
1122  char ch = s[index];
1123  if (IsLatin1(ch))
1124  {
1125  return CheckPunctuation(GetLatin1UnicodeCategory(ch));
1126  }
1127  return CheckPunctuation(CharUnicodeInfo.GetUnicodeCategory(s, index));
1128  }
1129 
1130  internal static bool CheckSeparator(UnicodeCategory uc)
1131  {
1132  switch (uc)
1133  {
1134  case UnicodeCategory.SpaceSeparator:
1135  case UnicodeCategory.LineSeparator:
1136  case UnicodeCategory.ParagraphSeparator:
1137  return true;
1138  default:
1139  return false;
1140  }
1141  }
1142 
1143  private static bool IsSeparatorLatin1(char c)
1144  {
1145  if (c != ' ')
1146  {
1147  return c == '\u00a0';
1148  }
1149  return true;
1150  }
1151 
1156  [__DynamicallyInvokable]
1157  public static bool IsSeparator(char c)
1158  {
1159  if (IsLatin1(c))
1160  {
1161  return IsSeparatorLatin1(c);
1162  }
1163  return CheckSeparator(CharUnicodeInfo.GetUnicodeCategory(c));
1164  }
1165 
1175  [__DynamicallyInvokable]
1176  public static bool IsSeparator(string s, int index)
1177  {
1178  if (s == null)
1179  {
1180  throw new ArgumentNullException("s");
1181  }
1182  if ((uint)index >= (uint)s.Length)
1183  {
1184  throw new ArgumentOutOfRangeException("index");
1185  }
1186  char c = s[index];
1187  if (IsLatin1(c))
1188  {
1189  return IsSeparatorLatin1(c);
1190  }
1191  return CheckSeparator(CharUnicodeInfo.GetUnicodeCategory(s, index));
1192  }
1193 
1198  [__DynamicallyInvokable]
1199  public static bool IsSurrogate(char c)
1200  {
1201  if (c >= '\ud800')
1202  {
1203  return c <= '\udfff';
1204  }
1205  return false;
1206  }
1207 
1217  [__DynamicallyInvokable]
1218  public static bool IsSurrogate(string s, int index)
1219  {
1220  if (s == null)
1221  {
1222  throw new ArgumentNullException("s");
1223  }
1224  if ((uint)index >= (uint)s.Length)
1225  {
1226  throw new ArgumentOutOfRangeException("index");
1227  }
1228  return IsSurrogate(s[index]);
1229  }
1230 
1231  internal static bool CheckSymbol(UnicodeCategory uc)
1232  {
1233  switch (uc)
1234  {
1235  case UnicodeCategory.MathSymbol:
1236  case UnicodeCategory.CurrencySymbol:
1237  case UnicodeCategory.ModifierSymbol:
1238  case UnicodeCategory.OtherSymbol:
1239  return true;
1240  default:
1241  return false;
1242  }
1243  }
1244 
1249  [__DynamicallyInvokable]
1250  public static bool IsSymbol(char c)
1251  {
1252  if (IsLatin1(c))
1253  {
1254  return CheckSymbol(GetLatin1UnicodeCategory(c));
1255  }
1256  return CheckSymbol(CharUnicodeInfo.GetUnicodeCategory(c));
1257  }
1258 
1268  [__DynamicallyInvokable]
1269  public static bool IsSymbol(string s, int index)
1270  {
1271  if (s == null)
1272  {
1273  throw new ArgumentNullException("s");
1274  }
1275  if ((uint)index >= (uint)s.Length)
1276  {
1277  throw new ArgumentOutOfRangeException("index");
1278  }
1279  if (IsLatin1(s[index]))
1280  {
1281  return CheckSymbol(GetLatin1UnicodeCategory(s[index]));
1282  }
1283  return CheckSymbol(CharUnicodeInfo.GetUnicodeCategory(s, index));
1284  }
1285 
1295  [__DynamicallyInvokable]
1296  public static bool IsUpper(string s, int index)
1297  {
1298  if (s == null)
1299  {
1300  throw new ArgumentNullException("s");
1301  }
1302  if ((uint)index >= (uint)s.Length)
1303  {
1304  throw new ArgumentOutOfRangeException("index");
1305  }
1306  char c = s[index];
1307  if (IsLatin1(c))
1308  {
1309  if (IsAscii(c))
1310  {
1311  if (c >= 'A')
1312  {
1313  return c <= 'Z';
1314  }
1315  return false;
1316  }
1317  return GetLatin1UnicodeCategory(c) == UnicodeCategory.UppercaseLetter;
1318  }
1319  return CharUnicodeInfo.GetUnicodeCategory(s, index) == UnicodeCategory.UppercaseLetter;
1320  }
1321 
1331  [__DynamicallyInvokable]
1332  public static bool IsWhiteSpace(string s, int index)
1333  {
1334  if (s == null)
1335  {
1336  throw new ArgumentNullException("s");
1337  }
1338  if ((uint)index >= (uint)s.Length)
1339  {
1340  throw new ArgumentOutOfRangeException("index");
1341  }
1342  if (IsLatin1(s[index]))
1343  {
1344  return IsWhiteSpaceLatin1(s[index]);
1345  }
1346  return CharUnicodeInfo.IsWhiteSpace(s, index);
1347  }
1348 
1352  public static UnicodeCategory GetUnicodeCategory(char c)
1353  {
1354  if (IsLatin1(c))
1355  {
1356  return GetLatin1UnicodeCategory(c);
1357  }
1358  return CharUnicodeInfo.InternalGetUnicodeCategory(c);
1359  }
1360 
1369  public static UnicodeCategory GetUnicodeCategory(string s, int index)
1370  {
1371  if (s == null)
1372  {
1373  throw new ArgumentNullException("s");
1374  }
1375  if ((uint)index >= (uint)s.Length)
1376  {
1377  throw new ArgumentOutOfRangeException("index");
1378  }
1379  if (IsLatin1(s[index]))
1380  {
1381  return GetLatin1UnicodeCategory(s[index]);
1382  }
1383  return CharUnicodeInfo.InternalGetUnicodeCategory(s, index);
1384  }
1385 
1389  [__DynamicallyInvokable]
1390  public static double GetNumericValue(char c)
1391  {
1392  return CharUnicodeInfo.GetNumericValue(c);
1393  }
1394 
1403  [__DynamicallyInvokable]
1404  public static double GetNumericValue(string s, int index)
1405  {
1406  if (s == null)
1407  {
1408  throw new ArgumentNullException("s");
1409  }
1410  if ((uint)index >= (uint)s.Length)
1411  {
1412  throw new ArgumentOutOfRangeException("index");
1413  }
1414  return CharUnicodeInfo.GetNumericValue(s, index);
1415  }
1416 
1421  [__DynamicallyInvokable]
1422  public static bool IsHighSurrogate(char c)
1423  {
1424  if (c >= '\ud800')
1425  {
1426  return c <= '\udbff';
1427  }
1428  return false;
1429  }
1430 
1440  [__DynamicallyInvokable]
1441  public static bool IsHighSurrogate(string s, int index)
1442  {
1443  if (s == null)
1444  {
1445  throw new ArgumentNullException("s");
1446  }
1447  if (index < 0 || index >= s.Length)
1448  {
1449  throw new ArgumentOutOfRangeException("index");
1450  }
1451  return IsHighSurrogate(s[index]);
1452  }
1453 
1458  [__DynamicallyInvokable]
1459  public static bool IsLowSurrogate(char c)
1460  {
1461  if (c >= '\udc00')
1462  {
1463  return c <= '\udfff';
1464  }
1465  return false;
1466  }
1467 
1477  [__DynamicallyInvokable]
1478  public static bool IsLowSurrogate(string s, int index)
1479  {
1480  if (s == null)
1481  {
1482  throw new ArgumentNullException("s");
1483  }
1484  if (index < 0 || index >= s.Length)
1485  {
1486  throw new ArgumentOutOfRangeException("index");
1487  }
1488  return IsLowSurrogate(s[index]);
1489  }
1490 
1500  [__DynamicallyInvokable]
1501  public static bool IsSurrogatePair(string s, int index)
1502  {
1503  if (s == null)
1504  {
1505  throw new ArgumentNullException("s");
1506  }
1507  if (index < 0 || index >= s.Length)
1508  {
1509  throw new ArgumentOutOfRangeException("index");
1510  }
1511  if (index + 1 < s.Length)
1512  {
1513  return IsSurrogatePair(s[index], s[index + 1]);
1514  }
1515  return false;
1516  }
1517 
1523  [__DynamicallyInvokable]
1524  public static bool IsSurrogatePair(char highSurrogate, char lowSurrogate)
1525  {
1526  if (highSurrogate >= '\ud800' && highSurrogate <= '\udbff')
1527  {
1528  if (lowSurrogate >= '\udc00')
1529  {
1530  return lowSurrogate <= '\udfff';
1531  }
1532  return false;
1533  }
1534  return false;
1535  }
1536 
1542  [__DynamicallyInvokable]
1543  public static string ConvertFromUtf32(int utf32)
1544  {
1545  if (utf32 < 0 || utf32 > 1114111 || (utf32 >= 55296 && utf32 <= 57343))
1546  {
1547  throw new ArgumentOutOfRangeException("utf32", Environment.GetResourceString("ArgumentOutOfRange_InvalidUTF32"));
1548  }
1549  if (utf32 < 65536)
1550  {
1551  return ToString((char)utf32);
1552  }
1553  utf32 -= 65536;
1554  return new string(new char[2]
1555  {
1556  (char)(utf32 / 1024 + 55296),
1557  (char)(utf32 % 1024 + 56320)
1558  });
1559  }
1560 
1567  [__DynamicallyInvokable]
1568  public static int ConvertToUtf32(char highSurrogate, char lowSurrogate)
1569  {
1570  if (!IsHighSurrogate(highSurrogate))
1571  {
1572  throw new ArgumentOutOfRangeException("highSurrogate", Environment.GetResourceString("ArgumentOutOfRange_InvalidHighSurrogate"));
1573  }
1574  if (!IsLowSurrogate(lowSurrogate))
1575  {
1576  throw new ArgumentOutOfRangeException("lowSurrogate", Environment.GetResourceString("ArgumentOutOfRange_InvalidLowSurrogate"));
1577  }
1578  return (highSurrogate - 55296) * 1024 + (lowSurrogate - 56320) + 65536;
1579  }
1580 
1590  [__DynamicallyInvokable]
1591  public static int ConvertToUtf32(string s, int index)
1592  {
1593  if (s == null)
1594  {
1595  throw new ArgumentNullException("s");
1596  }
1597  if (index < 0 || index >= s.Length)
1598  {
1599  throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index"));
1600  }
1601  int num = s[index] - 55296;
1602  if (num >= 0 && num <= 2047)
1603  {
1604  if (num <= 1023)
1605  {
1606  if (index < s.Length - 1)
1607  {
1608  int num2 = s[index + 1] - 56320;
1609  if (num2 >= 0 && num2 <= 1023)
1610  {
1611  return num * 1024 + num2 + 65536;
1612  }
1613  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHighSurrogate", index), "s");
1614  }
1615  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHighSurrogate", index), "s");
1616  }
1617  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidLowSurrogate", index), "s");
1618  }
1619  return s[index];
1620  }
1621  }
1622 }
float ToSingle(IFormatProvider provider)
Converts the value of this instance to an equivalent single-precision floating-point number using the...
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
const char MaxValue
Represents the largest possible value of a T:System.Char. This field is constant.
Definition: Char.cs:17
static bool IsLetter(string s, int index)
Indicates whether the character at the specified position in a specified string is categorized as a U...
Definition: Char.cs:940
static bool IsControl(string s, int index)
Indicates whether the character at the specified position in a specified string is categorized as a c...
Definition: Char.cs:880
static long ToInt64(object value)
Converts the value of the specified object to a 64-bit signed integer.
Definition: Convert.cs:2506
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
static bool IsNumber(string s, int index)
Indicates whether the character at the specified position in a specified string is categorized as a n...
Definition: Char.cs:1076
static char ToLowerInvariant(char c)
Converts the value of a Unicode character to its lowercase equivalent using the casing rules of the i...
Definition: Char.cs:695
double ToDouble(IFormatProvider provider)
Converts the value of this instance to an equivalent double-precision floating-point number using the...
static bool IsLetterOrDigit(string s, int index)
Indicates whether the character at the specified position in a specified string is categorized as a l...
Definition: Char.cs:977
static bool IsSymbol(string s, int index)
Indicates whether the character at the specified position in a specified string is categorized as a s...
Definition: Char.cs:1269
int CompareTo(char value)
Compares this instance to a specified T:System.Char object and indicates whether this instance preced...
Definition: Char.cs:364
static bool IsSurrogatePair(string s, int index)
Indicates whether two adjacent T:System.Char objects at a specified position in a string form a surro...
Definition: Char.cs:1501
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
static int ConvertToUtf32(string s, int index)
Converts the value of a UTF-16 encoded character or surrogate pair at a specified position in a strin...
Definition: Char.cs:1591
Definition: __Canon.cs:3
static double GetNumericValue(char c)
Converts the specified numeric Unicode character to a double-precision floating point number.
Definition: Char.cs:1390
The exception that is thrown when the value of an argument is outside the allowable range of values a...
The exception that is thrown for invalid casting or explicit conversion.
char ToChar(IFormatProvider provider)
Converts the value of this instance to an equivalent Unicode character using the specified culture-sp...
Provides a mechanism for retrieving an object to control formatting.
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
Definition: DateTime.cs:13
DateTime ToDateTime(IFormatProvider provider)
Converts the value of this instance to an equivalent T:System.DateTime using the specified culture-sp...
sbyte ToSByte(IFormatProvider provider)
Converts the value of this instance to an equivalent 8-bit signed integer using the specified culture...
virtual TextInfo TextInfo
Gets the T:System.Globalization.TextInfo that defines the writing system associated with the culture.
Definition: CultureInfo.cs:480
static char ToUpperInvariant(char c)
Converts the value of a Unicode character to its uppercase equivalent using the casing rules of the i...
Definition: Char.cs:660
Defines a generalized type-specific comparison method that a value type or class implements to order ...
Definition: IComparable.cs:8
override bool Equals(object obj)
Returns a value that indicates whether this instance is equal to a specified object.
Definition: Char.cs:321
static bool IsLowSurrogate(string s, int index)
Indicates whether the T:System.Char object at the specified position in a string is a low surrogate.
Definition: Char.cs:1478
static bool IsUpper(string s, int index)
Indicates whether the character at the specified position in a specified string is categorized as an ...
Definition: Char.cs:1296
static bool IsUpper(char c)
Indicates whether the specified Unicode character is categorized as an uppercase letter.
Definition: Char.cs:530
static bool IsDigit(string s, int index)
Indicates whether the character at the specified position in a specified string is categorized as a d...
Definition: Char.cs:908
static bool IsHighSurrogate(char c)
Indicates whether the specified T:System.Char object is a high surrogate.
Definition: Char.cs:1422
override int GetHashCode()
Returns the hash code for this instance.
Definition: Char.cs:311
static char ToLower(char c, CultureInfo culture)
Converts the value of a specified Unicode character to its lowercase equivalent using specified cultu...
Definition: Char.cs:673
static char ToLower(char c)
Converts the value of a Unicode character to its lowercase equivalent.
Definition: Char.cs:686
static bool IsLetter(char c)
Indicates whether the specified Unicode character is categorized as a Unicode letter.
Definition: Char.cs:473
bool Equals(char obj)
Returns a value that indicates whether this instance is equal to the specified T:System....
Definition: Char.cs:336
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
static UnicodeCategory GetUnicodeCategory(char ch)
Gets the Unicode category of the specified character.
decimal ToDecimal(IFormatProvider provider)
Converts the value of this instance to an equivalent T:System.Decimal number using the specified cult...
static bool IsPunctuation(char c)
Indicates whether the specified Unicode character is categorized as a punctuation mark.
Definition: Char.cs:591
The exception that is thrown when the format of an argument is invalid, or when a composite format st...
int ToInt32(IFormatProvider provider)
Converts the value of this instance to an equivalent 32-bit signed integer using the specified cultur...
static bool IsLowSurrogate(char c)
Indicates whether the specified T:System.Char object is a low surrogate.
Definition: Char.cs:1459
int CompareTo(object value)
Compares this instance to a specified object and indicates whether this instance precedes,...
Definition: Char.cs:347
static bool TryParse(string s, out char result)
Converts the value of the specified string to its equivalent Unicode character. A return code indicat...
Definition: Char.cs:420
static bool IsDigit(char c)
Indicates whether the specified Unicode character is categorized as a decimal digit.
Definition: Char.cs:440
virtual char ToLower(char c)
Converts the specified character to lowercase.
Definition: TextInfo.cs:362
static char ToUpper(char c)
Converts the value of a Unicode character to its uppercase equivalent.
Definition: Char.cs:651
static ushort ToUInt16(object value)
Converts the value of the specified object to a 16-bit unsigned integer.
Definition: Convert.cs:1707
static bool IsSeparator(string s, int index)
Indicates whether the character at the specified position in a specified string is categorized as a s...
Definition: Char.cs:1176
object ToType(Type conversionType, IFormatProvider provider)
Converts the value of this instance to an T:System.Object of the specified T:System....
static sbyte ToSByte(object value)
Converts the value of the specified object to an 8-bit signed integer.
Definition: Convert.cs:909
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
ushort ToUInt16(IFormatProvider provider)
Converts the value of this instance to an equivalent 16-bit unsigned integer using the specified cult...
static bool IsControl(char c)
Indicates whether the specified Unicode character is categorized as a control character.
Definition: Char.cs:861
static bool IsSymbol(char c)
Indicates whether the specified Unicode character is categorized as a symbol character.
Definition: Char.cs:1250
static bool IsWhiteSpace(char c)
Indicates whether the specified Unicode character is categorized as white space.
Definition: Char.cs:516
static uint ToUInt32(object value)
Converts the value of the specified object to a 32-bit unsigned integer.
Definition: Convert.cs:2235
short ToInt16(IFormatProvider provider)
Converts the value of this instance to an equivalent 16-bit signed integer using the specified cultur...
static bool IsSurrogatePair(char highSurrogate, char lowSurrogate)
Indicates whether the two specified T:System.Char objects form a surrogate pair.
Definition: Char.cs:1524
static bool IsLetterOrDigit(char c)
Indicates whether the specified Unicode character is categorized as a letter or a decimal digit.
Definition: Char.cs:621
static int ConvertToUtf32(char highSurrogate, char lowSurrogate)
Converts the value of a UTF-16 encoded surrogate pair into a Unicode code point.
Definition: Char.cs:1568
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
Definition: CultureInfo.cs:120
long ToInt64(IFormatProvider provider)
Converts the value of this instance to an equivalent 64-bit signed integer using the specified cultur...
The exception that is thrown when one of the arguments provided to a method is not valid.
Retrieves information about a Unicode character. This class cannot be inherited.
TypeCode GetTypeCode()
Returns the T:System.TypeCode for value type T:System.Char.
Definition: Char.cs:702
static bool IsNumber(char c)
Indicates whether the specified Unicode character is categorized as a number.
Definition: Char.cs:1049
UnicodeCategory
Defines the Unicode category of a character.
const char MinValue
Represents the smallest possible value of a T:System.Char. This field is constant.
Definition: Char.cs:21
static bool IsLower(string s, int index)
Indicates whether the character at the specified position in a specified string is categorized as a l...
Definition: Char.cs:1005
static double GetNumericValue(char ch)
Gets the numeric value associated with the specified character.
static bool IsPunctuation(string s, int index)
Indicates whether the character at the specified position in a specified string is categorized as a p...
Definition: Char.cs:1112
static byte ToByte(object value)
Converts the value of the specified object to an 8-bit unsigned integer.
Definition: Convert.cs:1186
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition: IEquatable.cs:6
static bool IsSurrogate(char c)
Indicates whether the specified character has a surrogate code unit.
Definition: Char.cs:1199
static string ToString(char c)
Converts the specified Unicode character to its equivalent string representation.
Definition: Char.cs:389
static short ToInt16(object value)
Converts the value of the specified object to a 16-bit signed integer.
Definition: Convert.cs:1452
Specifies that the class can be serialized.
static bool IsWhiteSpace(string s, int index)
Indicates whether the character at the specified position in a specified string is categorized as whi...
Definition: Char.cs:1332
override string ToString()
Converts the value of this instance to its equivalent string representation.
Definition: Char.cs:372
ulong ToUInt64(IFormatProvider provider)
Converts the value of this instance to an equivalent 64-bit unsigned integer using the specified cult...
static char ToUpper(char c, CultureInfo culture)
Converts the value of a specified Unicode character to its uppercase equivalent using specified cultu...
Definition: Char.cs:638
static ulong ToUInt64(object value)
Converts the value of the specified object to a 64-bit unsigned integer.
Definition: Convert.cs:2727
static int ToInt32(object value)
Converts the value of the specified object to a 32-bit signed integer.
Definition: Convert.cs:1974
static UnicodeCategory GetUnicodeCategory(char c)
Categorizes a specified Unicode character into a group identified by one of the T:System....
Definition: Char.cs:1352
byte ToByte(IFormatProvider provider)
Converts the value of this instance to an equivalent 8-bit unsigned integer using the specified cultu...
static bool IsLower(char c)
Indicates whether the specified Unicode character is categorized as a lowercase letter.
Definition: Char.cs:552
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
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
static char Parse(string s)
Converts the value of the specified string to its equivalent Unicode character.
Definition: Char.cs:401
Represents a character as a UTF-16 code unit.
Definition: Char.cs:11
static bool IsHighSurrogate(string s, int index)
Indicates whether the T:System.Char object at the specified position in a string is a high surrogate.
Definition: Char.cs:1441
static bool IsSurrogate(string s, int index)
Indicates whether the character at the specified position in a specified string has a surrogate code ...
Definition: Char.cs:1218
uint ToUInt32(IFormatProvider provider)
Converts the value of this instance to an equivalent 32-bit unsigned integer using the specified cult...
static string ConvertFromUtf32(int utf32)
Converts the specified Unicode code point into a UTF-16 encoded string.
Definition: Char.cs:1543
static bool IsSeparator(char c)
Indicates whether the specified Unicode character is categorized as a separator character.
Definition: Char.cs:1157
string ToString(IFormatProvider provider)
Converts the value of this instance to its equivalent string representation using the specified cultu...
Definition: Char.cs:380
static double GetNumericValue(string s, int index)
Converts the numeric Unicode character at the specified position in a specified string to a double-pr...
Definition: Char.cs:1404
static UnicodeCategory GetUnicodeCategory(string s, int index)
Categorizes the character at the specified position in a specified string into a group identified by ...
Definition: Char.cs:1369