C# 문자열 속성

PHPz
풀어 주다: 2023-09-15 19:25:02
앞으로
770명이 탐색했습니다.

C# 字符串属性

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

Chars 2 Length Example 예제를 살펴보겠습니다.- 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으로 문의하세요.
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!