>  기사  >  백엔드 개발  >  C# 문자열 속성

C# 문자열 속성

PHPz
PHPz앞으로
2023-09-15 19:25:02821검색

C# 字符串属性

다음은 C#의 String 클래스 속성입니다.

Chars2LengthExample예제를 살펴보겠습니다.- Live Demonstration이제 다른 예를 살펴보겠습니다.실시간 시연
Sr

의 지정된 위치에 있는 현재 String 개체 Char 개체를 가져옵니다.

현재 String 개체의 문자 수를 가져옵니다.

using System;
public class Demo {
   public static void Main() {
      string str1 = "h8b9";
      string str2 = "abcdef";
      Console.WriteLine("Is string1 null or empty? = "+string.IsNullOrEmpty(str1));
      Console.WriteLine("Is string2 null or empty? = "+string.IsNullOrEmpty(str2));
      bool val = str1 != str2;
      Console.WriteLine("Is str1 equal to str2? = "+val);
      for (int i = 0; i < str1.Length; i++) {
         if (Char.IsLetter(str1[i]))
            Console.WriteLine(""+str1[i]+" is a letter");
         else
            Console.WriteLine(""+str1[i]+" is a number");
      }
   }
}
Output이렇게 하면 다음과 같은 출력이 생성됩니다.-

Is string1 null or empty? = False
Is string2 null or empty? = False
Is str1 equal to str2? = True
h is a letter
8 is a number
b is a letter
9 is a number

Example

using System;
public class Demo {
   public static void Main() {
      string str1 = "hijklm";
      string str2 = String.Empty;
      Console.WriteLine("Is string1 null or whitespace? = "+String.IsNullOrWhiteSpace(str1));
      Console.WriteLine("Is string2 null or whitespace? = "+String.IsNullOrWhiteSpace(str2));
      Console.WriteLine("String1 length = "+str1.Length);
      Console.WriteLine("String2 length = "+str1.Length);
      Console.WriteLine("String length = "+"demo".Length);
   }
}

Output

이렇게 하면 다음 예제가 생성됩니다. -

Is string1 null or whitespace? = False
Is string2 null or whitespace? = True
String1 length = 6
String2 length = 6
String length = 4

위 내용은 C# 문자열 속성의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 tutorialspoint.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제