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

C#에서 문자열의 첫 번째 문자를 찾는 방법은 무엇입니까?

<시간/>

첫 번째 문자를 얻으려면 substring() 메서드를 사용하십시오.

다음 isour 문자열을 가정해 봅시다 -

string str = "Welcome to the Planet!";

이제 첫 번째 문자를 가져오려면 substring() 메서드에서 값을 1로 설정합니다.

string res = str.Substring(0, 1);

전체 코드를 보자 -

using System;
public class Demo {
   public static void Main() {
      string str = "Welcome to the Planet!";
      string res = str.Substring(0, 1);
      Console.WriteLine(res);
   }
}

출력

W