Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions snippets/csharp/System/Char/CompareTo/compareto.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// <snippet19>
using System;

public class CompareToSample {
public static void Main() {
char chA = 'A';
char chB = 'B';
public class CompareToSample
{
public static void Main()
{
char chA = 'A';
char chB = 'B';

Console.WriteLine(chA.CompareTo('A')); // Output: "0" (meaning they're equal)
Console.WriteLine('b'.CompareTo(chB)); // Output: "32" (meaning 'b' is greater than 'B' by 32)
Console.WriteLine(chA.CompareTo(chB)); // Output: "-1" (meaning 'A' is less than 'B' by 1)
}
Console.WriteLine(chA.CompareTo('A')); // Output: "0" (meaning they're equal)
Console.WriteLine('b'.CompareTo(chB)); // Output: "32" (meaning 'b' is greater than 'B' by 32)
Console.WriteLine(chA.CompareTo(chB)); // Output: "-1" (meaning 'A' is less than 'B' by 1)
}
}
// </snippet19>
114 changes: 56 additions & 58 deletions snippets/csharp/System/Char/ConvertFromUtf32/utf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,68 +7,66 @@ class Sample
{
public static void Main()
{
int letterA = 0x0041; //U+00041 = LATIN CAPITAL LETTER A
int music = 0x1D161; //U+1D161 = MUSICAL SYMBOL SIXTEENTH NOTE
string s1;
string comment = "Create a UTF-16 encoded string from a code point.";
string comment1b = "Create a code point from a UTF-16 encoded string.";
string comment2b = "Create a code point from a surrogate pair at a certain position in a string.";
string comment2c = "Create a code point from a high surrogate and a low surrogate code point.";

// Convert code point U+0041 to UTF-16. The UTF-16 equivalent of
// U+0041 is a Char with hexadecimal value 0041.

Console.WriteLine(comment);
s1 = Char.ConvertFromUtf32(letterA);
Console.Write(" 1a) 0x{0:X} => ", letterA);
Show(s1);
Console.WriteLine();

// Convert the lone UTF-16 character to a code point.

Console.WriteLine(comment1b);
letterA = Char.ConvertToUtf32(s1, 0);
Console.Write(" 1b) ");
Show(s1);
Console.WriteLine(" => 0x{0:X}", letterA);
Console.WriteLine();

// -------------------------------------------------------------------

// Convert the code point U+1D161 to UTF-16. The UTF-16 equivalent of
// U+1D161 is a surrogate pair with hexadecimal values D834 and DD61.

Console.WriteLine(comment);
s1 = Char.ConvertFromUtf32(music);
Console.Write(" 2a) 0x{0:X} => ", music);
Show(s1);
Console.WriteLine();

// Convert the surrogate pair in the string at index position
// zero to a code point.

Console.WriteLine(comment2b);
music = Char.ConvertToUtf32(s1, 0);
Console.Write(" 2b) ");
Show(s1);
Console.WriteLine(" => 0x{0:X}", music);

// Convert the high and low characters in the surrogate pair into a code point.

Console.WriteLine(comment2c);
music = Char.ConvertToUtf32(s1[0], s1[1]);
Console.Write(" 2c) ");
Show(s1);
Console.WriteLine(" => 0x{0:X}", music);
int letterA = 0x0041; //U+00041 = LATIN CAPITAL LETTER A
int music = 0x1D161; //U+1D161 = MUSICAL SYMBOL SIXTEENTH NOTE
string s1;
string comment = "Create a UTF-16 encoded string from a code point.";
string comment1b = "Create a code point from a UTF-16 encoded string.";
string comment2b = "Create a code point from a surrogate pair at a certain position in a string.";
string comment2c = "Create a code point from a high surrogate and a low surrogate code point.";

// Convert code point U+0041 to UTF-16. The UTF-16 equivalent of
// U+0041 is a Char with hexadecimal value 0041.

Console.WriteLine(comment);
s1 = char.ConvertFromUtf32(letterA);
Console.Write($" 1a) 0x{letterA:X} => ");
Show(s1);
Console.WriteLine();

// Convert the lone UTF-16 character to a code point.

Console.WriteLine(comment1b);
letterA = char.ConvertToUtf32(s1, 0);
Console.Write(" 1b) ");
Show(s1);
Console.WriteLine($" => 0x{letterA:X}");
Console.WriteLine();

// -------------------------------------------------------------------

// Convert the code point U+1D161 to UTF-16. The UTF-16 equivalent of
// U+1D161 is a surrogate pair with hexadecimal values D834 and DD61.

Console.WriteLine(comment);
s1 = char.ConvertFromUtf32(music);
Console.Write($" 2a) 0x{music:X} => ");
Show(s1);
Console.WriteLine();

// Convert the surrogate pair in the string at index position
// zero to a code point.

Console.WriteLine(comment2b);
music = char.ConvertToUtf32(s1, 0);
Console.Write(" 2b) ");
Show(s1);
Console.WriteLine($" => 0x{music:X}");

// Convert the high and low characters in the surrogate pair into a code point.

Console.WriteLine(comment2c);
music = char.ConvertToUtf32(s1[0], s1[1]);
Console.Write(" 2c) ");
Show(s1);
Console.WriteLine($" => 0x{music:X}");
}

private static void Show(string s)
{
for (int x = 0; x < s.Length; x++)
for (int x = 0; x < s.Length; x++)
{
Console.Write("0x{0:X}{1}",
(int)s[x],
((x == s.Length-1)? String.Empty : ", "));
Console.Write($"0x{(int)s[x]:X}{((x == s.Length - 1) ? string.Empty : ", ")}");
}
}
}
Expand All @@ -88,4 +86,4 @@ Create a code point from a high surrogate and a low surrogate code point.
2c) 0xD834, 0xDD61 => 0x1D161

*/
//</snippet1>
//</snippet1>
16 changes: 9 additions & 7 deletions snippets/csharp/System/Char/Equals/equals.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// <snippet20>
using System;

public class EqualsSample {
public static void Main() {
char chA = 'A';
char chB = 'B';
public class EqualsSample
{
public static void Main()
{
char chA = 'A';
char chB = 'B';

Console.WriteLine(chA.Equals('A')); // Output: "True"
Console.WriteLine('b'.Equals(chB)); // Output: "False"
}
Console.WriteLine(chA.Equals('A')); // Output: "True"
Console.WriteLine('b'.Equals(chB)); // Output: "False"
}
}
// </snippet20>
14 changes: 8 additions & 6 deletions snippets/csharp/System/Char/GetNumericValue/getnumericvalue.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// <snippet1>
using System;

public class GetNumericValueSample {
public static void Main() {
string str = "input: 1";
public class GetNumericValueSample
{
public static void Main()
{
string str = "input: 1";

Console.WriteLine(Char.GetNumericValue('8')); // Output: "8"
Console.WriteLine(Char.GetNumericValue(str, 7)); // Output: "1"
}
Console.WriteLine(char.GetNumericValue('8')); // Output: "8"
Console.WriteLine(char.GetNumericValue(str, 7)); // Output: "1"
}
}
// </snippet1>
158 changes: 78 additions & 80 deletions snippets/csharp/System/Char/GetNumericValue/getnumericvalue1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,88 +2,86 @@

public class Example
{
public static void Main()
{
Overload1();
Console.WriteLine();
Overload2();
}
public static void Main()
{
Overload1();
Console.WriteLine();
Overload2();
}

private static void Overload1()
{
// <Snippet2>
int utf32 = 0x10107; // AEGEAN NUMBER ONE
string surrogate = Char.ConvertFromUtf32(utf32);
foreach (var ch in surrogate)
Console.WriteLine("U+{0:X4}: {1} ", Convert.ToUInt16(ch),
Char.GetNumericValue(ch));
private static void Overload1()
{
// <Snippet2>
int utf32 = 0x10107; // AEGEAN NUMBER ONE
string surrogate = char.ConvertFromUtf32(utf32);
foreach (char ch in surrogate)
Console.WriteLine($"U+{Convert.ToUInt16(ch):X4}: {char.GetNumericValue(ch)} ");

// The example displays the following output:
// U+D800: -1
// U+DD07: -1
// </Snippet2>
}
// The example displays the following output:
// U+D800: -1
// U+DD07: -1
// </Snippet2>
}

private static void Overload2()
{
// <Snippet3>
// Define a UTF32 value for each character in the
// Aegean numbering system.
for (int utf32 = 0x10107; utf32 <= 0x10133; utf32++) {
string surrogate = Char.ConvertFromUtf32(utf32);
for (int ctr = 0; ctr < surrogate.Length; ctr++)
Console.Write("U+{0:X4} at position {1}: {2} ",
Convert.ToUInt16(surrogate[ctr]), ctr,
Char.GetNumericValue(surrogate, ctr));
private static void Overload2()
{
// <Snippet3>
// Define a UTF32 value for each character in the
// Aegean numbering system.
for (int utf32 = 0x10107; utf32 <= 0x10133; utf32++)
{
string surrogate = char.ConvertFromUtf32(utf32);
for (int ctr = 0; ctr < surrogate.Length; ctr++)
Console.Write($"U+{Convert.ToUInt16(surrogate[ctr]):X4} at position {ctr}: {char.GetNumericValue(surrogate, ctr)} ");

Console.WriteLine();
}
// The example displays the following output:
// U+D800 at position 0: 1 U+DD07 at position 1: -1
// U+D800 at position 0: 2 U+DD08 at position 1: -1
// U+D800 at position 0: 3 U+DD09 at position 1: -1
// U+D800 at position 0: 4 U+DD0A at position 1: -1
// U+D800 at position 0: 5 U+DD0B at position 1: -1
// U+D800 at position 0: 6 U+DD0C at position 1: -1
// U+D800 at position 0: 7 U+DD0D at position 1: -1
// U+D800 at position 0: 8 U+DD0E at position 1: -1
// U+D800 at position 0: 9 U+DD0F at position 1: -1
// U+D800 at position 0: 10 U+DD10 at position 1: -1
// U+D800 at position 0: 20 U+DD11 at position 1: -1
// U+D800 at position 0: 30 U+DD12 at position 1: -1
// U+D800 at position 0: 40 U+DD13 at position 1: -1
// U+D800 at position 0: 50 U+DD14 at position 1: -1
// U+D800 at position 0: 60 U+DD15 at position 1: -1
// U+D800 at position 0: 70 U+DD16 at position 1: -1
// U+D800 at position 0: 80 U+DD17 at position 1: -1
// U+D800 at position 0: 90 U+DD18 at position 1: -1
// U+D800 at position 0: 100 U+DD19 at position 1: -1
// U+D800 at position 0: 200 U+DD1A at position 1: -1
// U+D800 at position 0: 300 U+DD1B at position 1: -1
// U+D800 at position 0: 400 U+DD1C at position 1: -1
// U+D800 at position 0: 500 U+DD1D at position 1: -1
// U+D800 at position 0: 600 U+DD1E at position 1: -1
// U+D800 at position 0: 700 U+DD1F at position 1: -1
// U+D800 at position 0: 800 U+DD20 at position 1: -1
// U+D800 at position 0: 900 U+DD21 at position 1: -1
// U+D800 at position 0: 1000 U+DD22 at position 1: -1
// U+D800 at position 0: 2000 U+DD23 at position 1: -1
// U+D800 at position 0: 3000 U+DD24 at position 1: -1
// U+D800 at position 0: 4000 U+DD25 at position 1: -1
// U+D800 at position 0: 5000 U+DD26 at position 1: -1
// U+D800 at position 0: 6000 U+DD27 at position 1: -1
// U+D800 at position 0: 7000 U+DD28 at position 1: -1
// U+D800 at position 0: 8000 U+DD29 at position 1: -1
// U+D800 at position 0: 9000 U+DD2A at position 1: -1
// U+D800 at position 0: 10000 U+DD2B at position 1: -1
// U+D800 at position 0: 20000 U+DD2C at position 1: -1
// U+D800 at position 0: 30000 U+DD2D at position 1: -1
// U+D800 at position 0: 40000 U+DD2E at position 1: -1
// U+D800 at position 0: 50000 U+DD2F at position 1: -1
// U+D800 at position 0: 60000 U+DD30 at position 1: -1
// U+D800 at position 0: 70000 U+DD31 at position 1: -1
// U+D800 at position 0: 80000 U+DD32 at position 1: -1
// U+D800 at position 0: 90000 U+DD33 at position 1: -1
// </Snippet3>
}
Console.WriteLine();
}
// The example displays the following output:
// U+D800 at position 0: 1 U+DD07 at position 1: -1
// U+D800 at position 0: 2 U+DD08 at position 1: -1
// U+D800 at position 0: 3 U+DD09 at position 1: -1
// U+D800 at position 0: 4 U+DD0A at position 1: -1
// U+D800 at position 0: 5 U+DD0B at position 1: -1
// U+D800 at position 0: 6 U+DD0C at position 1: -1
// U+D800 at position 0: 7 U+DD0D at position 1: -1
// U+D800 at position 0: 8 U+DD0E at position 1: -1
// U+D800 at position 0: 9 U+DD0F at position 1: -1
// U+D800 at position 0: 10 U+DD10 at position 1: -1
// U+D800 at position 0: 20 U+DD11 at position 1: -1
// U+D800 at position 0: 30 U+DD12 at position 1: -1
// U+D800 at position 0: 40 U+DD13 at position 1: -1
// U+D800 at position 0: 50 U+DD14 at position 1: -1
// U+D800 at position 0: 60 U+DD15 at position 1: -1
// U+D800 at position 0: 70 U+DD16 at position 1: -1
// U+D800 at position 0: 80 U+DD17 at position 1: -1
// U+D800 at position 0: 90 U+DD18 at position 1: -1
// U+D800 at position 0: 100 U+DD19 at position 1: -1
// U+D800 at position 0: 200 U+DD1A at position 1: -1
// U+D800 at position 0: 300 U+DD1B at position 1: -1
// U+D800 at position 0: 400 U+DD1C at position 1: -1
// U+D800 at position 0: 500 U+DD1D at position 1: -1
// U+D800 at position 0: 600 U+DD1E at position 1: -1
// U+D800 at position 0: 700 U+DD1F at position 1: -1
// U+D800 at position 0: 800 U+DD20 at position 1: -1
// U+D800 at position 0: 900 U+DD21 at position 1: -1
// U+D800 at position 0: 1000 U+DD22 at position 1: -1
// U+D800 at position 0: 2000 U+DD23 at position 1: -1
// U+D800 at position 0: 3000 U+DD24 at position 1: -1
// U+D800 at position 0: 4000 U+DD25 at position 1: -1
// U+D800 at position 0: 5000 U+DD26 at position 1: -1
// U+D800 at position 0: 6000 U+DD27 at position 1: -1
// U+D800 at position 0: 7000 U+DD28 at position 1: -1
// U+D800 at position 0: 8000 U+DD29 at position 1: -1
// U+D800 at position 0: 9000 U+DD2A at position 1: -1
// U+D800 at position 0: 10000 U+DD2B at position 1: -1
// U+D800 at position 0: 20000 U+DD2C at position 1: -1
// U+D800 at position 0: 30000 U+DD2D at position 1: -1
// U+D800 at position 0: 40000 U+DD2E at position 1: -1
// U+D800 at position 0: 50000 U+DD2F at position 1: -1
// U+D800 at position 0: 60000 U+DD30 at position 1: -1
// U+D800 at position 0: 70000 U+DD31 at position 1: -1
// U+D800 at position 0: 80000 U+DD32 at position 1: -1
// U+D800 at position 0: 90000 U+DD33 at position 1: -1
// </Snippet3>
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// <snippet1>
using System;

public class GetUnicodeCategorySample {
public static void Main() {
char ch2 = '2';
string str = "Upper Case";
public class GetUnicodeCategorySample
{
public static void Main()
{
char ch2 = '2';
string str = "Upper Case";

Console.WriteLine(Char.GetUnicodeCategory('a')); // Output: "LowercaseLetter"
Console.WriteLine(Char.GetUnicodeCategory(ch2)); // Output: "DecimalDigitNumber"
Console.WriteLine(Char.GetUnicodeCategory(str, 6)); // Output: "UppercaseLetter"
}
Console.WriteLine(char.GetUnicodeCategory('a')); // Output: "LowercaseLetter"
Console.WriteLine(char.GetUnicodeCategory(ch2)); // Output: "DecimalDigitNumber"
Console.WriteLine(char.GetUnicodeCategory(str, 6)); // Output: "UppercaseLetter"
}
}
// </snippet1>
Loading
Loading