투케이2K

64. (C#/NET) [Mac Os] [문법] String 문자열 Substring 사용해 부분 문자열 출력 실시 본문

C샵 (NET)

64. (C#/NET) [Mac Os] [문법] String 문자열 Substring 사용해 부분 문자열 출력 실시

투케이2K 2024. 3. 16. 10:39
반응형

[개발 환경 설정]

개발 언어 : C# / NET

 

[소스 코드]

using System;
using System.Collections;
using System.Data;
using System.Diagnostics.Tracing;
using System.Text;
using System.Web;

namespace testProject {


    // [프로그램 동작 클래스]
    class Program {

        static void Main(string[] args){

            // [변수 선언 실시]
            string str = "hello twok nice!!";


            // [Substring 사용해 부분 문자열 출력] : [시작 번지 ~ 지정된 글자 수]
            string zero_to_four = str.Substring(0, 4); // [0, 1, 2, 3]
            
            string six_to_ten = str.Substring(6, 10); // [6, 7, 8, 9, 10, 11, 12, 13, 14, 15]


            // [로그 출력 수행]
            Console.WriteLine($"");
            Console.WriteLine($"------------------------------------------");
            Console.WriteLine($"[Main] : [Log]");
            Console.WriteLine($"------------------------------------------");
            Console.WriteLine($"str : {str}");
            Console.WriteLine($"------------------------------------------");
            Console.WriteLine($"zero_to_four : {zero_to_four}");
            Console.WriteLine($"------------------------------------------");
            Console.WriteLine($"six_to_ten : {six_to_ten}");
            Console.WriteLine($"------------------------------------------");
            Console.WriteLine($"");

        }

    }

}
 

[결과 출력]

 

 

반응형
Comments