Computer >> 컴퓨터 >  >> 프로그램 작성 >> C#

C# String.IsNormalized 메서드

<시간/>

C#의 String.IsNormalized() 메서드는 이 문자열이 특정 유니코드 정규화 형식인지 여부를 나타내는 데 사용됩니다.

구문

구문은 다음과 같습니다 -

public bool IsNormalized ();
public bool IsNormalized (System.Text.NormalizationForm normalizationForm);

위의 normalizationForm 매개변수는 유니코드 정규화 형식입니다.

예시

이제 예를 살펴보겠습니다 -

using System;
public class Demo {
   public static void Main(String[] args) {
      string str1 = "Ryan";
      string str2 = "Matt";
      Console.WriteLine("String 1 = "+str1);
      Console.WriteLine("HashCode of String 1 = "+str1.GetHashCode());
      Console.WriteLine("Index of character 'k' in str1 = " + str1.IndexOf("k"));
      Console.WriteLine("\nString 2 = "+str2);
      Console.WriteLine("HashCode of String 2 = "+str2.GetHashCode());
      Console.WriteLine("Index of character 'k' in str2 =" + str2.IndexOf("k"));
      bool res1 = str1.Contains(str2);
      res1 = str1.IsNormalized();
      Console.WriteLine("\nThe str1 is in normalized form = "+res1);
      bool res2 = str1.Contains(str2);
      res2 = str2.IsNormalized();
      Console.WriteLine("The str2 is in normalized form = "+res2);
   }
}

출력

이것은 다음과 같은 출력을 생성합니다 -

String 1 = Ryan
HashCode of String 1 = 1580592915
Index of character 'k' in str1 = -1
String 2 = Matt
HashCode of String 2 = -1920007383
Index of character 'k' in str2 =-1
The str1 is in normalized form = True
The str2 is in normalized form = True

예시

이제 다른 예를 살펴보겠습니다 -

using System;
using System.Text;
public class Demo {
   public static void Main(String[] args) {
      string str1 = "Imagine Dragons";
      string str2 = "Imagine";
      Console.WriteLine("String 1 = "+str1);
      Console.WriteLine("HashCode of String 1 = "+str1.GetHashCode());
      Console.WriteLine("String 2 = "+str2);
      Console.WriteLine("HashCode of String 2 = "+str2.GetHashCode());
      Console.WriteLine("String 1 is equal to String 2: {0}", str1.Equals(str2));
      Console.WriteLine("str1 is normalized to form C? = {0}",
      str1.IsNormalized(NormalizationForm.FormC));
      Console.WriteLine("str2 is normalized to form C? = {0}", (str2.IsNormalized(NormalizationForm.FormC)));
      Console.WriteLine("str1 is normalized to form D? = {0}", str1.IsNormalized(NormalizationForm.FormD));
      Console.WriteLine("str2 is normalized to form D? = {0}", str2.IsNormalized(NormalizationForm.FormD));
      Console.WriteLine("str1 is normalized to form KC? = {0}", str1.IsNormalized(NormalizationForm.FormKC));
      Console.WriteLine("str2 is normalized to form KC? = {0}", str2.IsNormalized(NormalizationForm.FormKC));
      Console.WriteLine("str1 is normalized to form KC? = {0}", str1.IsNormalized(NormalizationForm.FormKC));
      Console.WriteLine("str2 is normalized to form KC? = {0}", str2.IsNormalized(NormalizationForm.FormKC));
   }
}

출력

이것은 다음과 같은 출력을 생성합니다 -

String 1 = Imagine Dragons
HashCode of String 1 = -1546868095
String 2 = Imagine
HashCode of String 2 = -1414695254
String 1 is equal to String 2: False
str1 is normalized to form C? = True
str2 is normalized to form C? = True
str1 is normalized to form D? = True
str2 is normalized to form D? = True
str1 is normalized to form KC? = True
str2 is normalized to form KC? = True
str1 is normalized to form KC? = True
str2 is normalized to form KC? = True