當前位置: 首頁>>代碼示例>>C#>>正文


C# Char結構體代碼示例

本文整理匯總了C#中System.Char結構體的典型用法代碼示例。如果您正苦於以下問題:C# Char結構體的具體用法?C# Char怎麽用?C# Char使用的例子?那麽, 這裏精選的結構體代碼示例或許可以為您提供幫助。


Char結構體屬於System命名空間,在下文中一共展示了Char結構體的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main

//引入命名空間
using System;

public class CharStructureSample
{
    public static void Main()
    {
        char chA = 'A';
        char ch1 = '1';
        string str = "test string"; 

        Console.WriteLine(chA.CompareTo('B'));          //-----------  Output: "-1" (meaning 'A' is 1 less than 'B')
        Console.WriteLine(chA.Equals('A'));             //-----------  Output: "True"
        Console.WriteLine(Char.GetNumericValue(ch1));   //-----------  Output: "1"
        Console.WriteLine(Char.IsControl('\t'));        //-----------  Output: "True"
        Console.WriteLine(Char.IsDigit(ch1));           //-----------  Output: "True"
        Console.WriteLine(Char.IsLetter(','));          //-----------  Output: "False"
        Console.WriteLine(Char.IsLower('u'));           //-----------  Output: "True"
        Console.WriteLine(Char.IsNumber(ch1));          //-----------  Output: "True"
        Console.WriteLine(Char.IsPunctuation('.'));     //-----------  Output: "True"
        Console.WriteLine(Char.IsSeparator(str, 4));    //-----------  Output: "True"
        Console.WriteLine(Char.IsSymbol('+'));          //-----------  Output: "True"
        Console.WriteLine(Char.IsWhiteSpace(str, 4));   //-----------  Output: "True"
        Console.WriteLine(Char.Parse("S"));             //-----------  Output: "S"
        Console.WriteLine(Char.ToLower('M'));           //-----------  Output: "m"
        Console.WriteLine('x'.ToString());              //-----------  Output: "x"
    }
}
開發者ID:.NET開發者,項目名稱:System,代碼行數:28,代碼來源:Char

示例2: Main

//引入命名空間
using System;
using System.IO;

public class Example
{
   public static void Main()
   {
      StreamWriter sw = new StreamWriter("chars1.txt");
      char[] chars = { '\u0061', '\u0308' };
      string strng = new String(chars);
      sw.WriteLine(strng); 
      sw.Close();
   }
}
開發者ID:.NET開發者,項目名稱:System,代碼行數:15,代碼來源:Char

輸出:


示例3: Main

//引入命名空間
using System;
using System.IO;

public class Example
{
   public static void Main()
   {
      StreamWriter sw = new StreamWriter(@".\chars2.txt");
      int utf32 = 0x1D160;
      string surrogate = Char.ConvertFromUtf32(utf32);
      sw.WriteLine("U+{0:X6} UTF-32 = {1} ({2}) UTF-16", 
                   utf32, surrogate, ShowCodePoints(surrogate));
      sw.Close();                    
   }

   private static string ShowCodePoints(string value)
   {
      string retval = null;
      foreach (var ch in value)
         retval += String.Format("U+{0:X4} ", Convert.ToUInt16(ch));

      return retval.Trim();
   }
}
開發者ID:.NET開發者,項目名稱:System,代碼行數:25,代碼來源:Char

輸出:

U+01D160 UTF-32 = ð (U+D834 U+DD60) UTF-16

示例4: Main

//引入命名空間
using System;
using System.Globalization;

class Example
{
   public static void Main()
   {
      // Define a string with a variety of character categories.
      String s = "The red car drove down the long, narrow, secluded road.";
      // Determine the category of each character.
      foreach (var ch in s)
         Console.WriteLine("'{0}': {1}", ch, Char.GetUnicodeCategory(ch)); 
   }
}
開發者ID:.NET開發者,項目名稱:System,代碼行數:15,代碼來源:Char

輸出:

'T': UppercaseLetter
'h': LowercaseLetter
'e': LowercaseLetter
' ': SpaceSeparator
'r': LowercaseLetter
'e': LowercaseLetter
'd': LowercaseLetter
' ': SpaceSeparator
'c': LowercaseLetter
'a': LowercaseLetter
'r': LowercaseLetter
' ': SpaceSeparator
'd': LowercaseLetter
'r': LowercaseLetter
'o': LowercaseLetter
'v': LowercaseLetter
'e': LowercaseLetter
' ': SpaceSeparator
'd': LowercaseLetter
'o': LowercaseLetter
'w': LowercaseLetter
'n': LowercaseLetter
' ': SpaceSeparator
't': LowercaseLetter
'h': LowercaseLetter
'e': LowercaseLetter
' ': SpaceSeparator
'l': LowercaseLetter
'o': LowercaseLetter
'n': LowercaseLetter
'g': LowercaseLetter
',': OtherPunctuation
' ': SpaceSeparator
'n': LowercaseLetter
'a': LowercaseLetter
'r': LowercaseLetter
'r': LowercaseLetter
'o': LowercaseLetter
'w': LowercaseLetter
',': OtherPunctuation
' ': SpaceSeparator
's': LowercaseLetter
'e': LowercaseLetter
'c': LowercaseLetter
'l': LowercaseLetter
'u': LowercaseLetter
'd': LowercaseLetter
'e': LowercaseLetter
'd': LowercaseLetter
' ': SpaceSeparator
'r': LowercaseLetter
'o': LowercaseLetter
'a': LowercaseLetter
'd': LowercaseLetter
'.': OtherPunctuation

示例5: Main

//引入命名空間
using System;

public class Example
{
   public static void Main()
   {
      string result = String.Empty;
      for (int ctr = 0x10107; ctr <= 0x10110; ctr++)  // Range of Aegean numbers.
         result += Char.ConvertFromUtf32(ctr);

      Console.WriteLine("The string contains {0} characters.", result.Length); 
   }
}
開發者ID:.NET開發者,項目名稱:System,代碼行數:14,代碼來源:Char

輸出:

The string contains 20 characters.

示例6: Main

//引入命名空間
using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      string result = String.Empty;
      for (int ctr = 0x10107; ctr <= 0x10110; ctr++)  // Range of Aegean numbers.
         result += Char.ConvertFromUtf32(ctr);

      StringInfo si = new StringInfo(result);
      Console.WriteLine("The string contains {0} characters.", 
                        si.LengthInTextElements); 
   }
}
開發者ID:.NET開發者,項目名稱:System,代碼行數:17,代碼來源:Char

輸出:

The string contains 10 characters.

示例7: Main

//引入命名空間
using System;

public class Example
{
   public static void Main()
   {
      string combining = "\u0061\u0308";
      ShowString(combining);
      
      string normalized = combining.Normalize();
      ShowString(normalized);
   }

   private static void ShowString(string s)
   {
      Console.Write("Length of string: {0} (", s.Length);
      for (int ctr = 0; ctr < s.Length; ctr++) {
         Console.Write("U+{0:X4}", Convert.ToUInt16(s[ctr]));
         if (ctr != s.Length - 1) Console.Write(" ");
      } 
      Console.WriteLine(")\n");
   }
}
開發者ID:.NET開發者,項目名稱:System,代碼行數:24,代碼來源:Char

輸出:

Length of string: 2 (U+0061 U+0308)

Length of string: 1 (U+00E4)


注:本文中的System.Char結構體示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。