• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Char结构体代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# DictionaryEntry结构体代码示例发布时间:2022-05-26
下一篇:
C# Byte结构体代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap