C# 中的 Char.IsLowSurrogate(String, Int32) 方法


C# 中的 Char.IsLowSurrogate() 方法指示字串中指定位置處的 Char 物件是否是低替代字元。

語法

以下是語法 −

public static bool IsLowSurrogate (string str, int index);

在上面, str 是一個字串,而 index 是 str 中要評估的字元的位置。

示例

現在,讓我們看一個示例來實現 Char.IsLowSurrogate() 方法 −

using System;
public class Demo {
   public static void Main(){
      string str = new String(new char[] { 'k', 'm', 'g', 't', 'j', 'p', '\uDC00' });
      bool res = Char.IsLowSurrogate(str, 6);
      if (res)
         Console.WriteLine("Contains Low Surrogate value!");
      else
         Console.WriteLine("Does not contain Low Surrogate value!");
   }
}

輸出

此程式碼將生成以下輸出 −

Contains Low Surrogate value!

示例

現在,讓我們看另一個示例 −

using System;
public class Demo {
   public static void Main(){
      string str = new String(new char[] { 'k', 'm', 'g', 't', 'j', 'p', '\uDC00' });
      bool res = Char.IsLowSurrogate(str, 3);
      if (res)
         Console.WriteLine("Contains Low Surrogate value!");
      else
         Console.WriteLine("Does not contain Low Surrogate value!");
   }
}

輸出

此程式碼將生成以下輸出 −

Does not contain Low Surrogate value!

更新時間: 2019 年 11 月 12 日

82 次瀏覽

開啟您的職業

完成課程即可獲得認證

開始學習
廣告
© . All rights reserved.