[백준] C# : 열 개씩 끊어 출력하기 (11721번)

ssu_hyun·2022년 8월 11일
0

Data Structure & Algorithm

목록 보기
51/67
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Baekjoon
{
    class Program
    {
        static void Main(string[] args)
        {
            string word = Console.ReadLine();
            //  0, 10,  20, 30에서 문자를 잘라야함
            int count = 0;

             while (true)
            {
                try
                {
                    Console.WriteLine(word.Substring(count, 10));  // 0위치에서 길이 10의 단어를 끊어 출력
                }
                // 종료 조건
                catch
                {
                    Console.WriteLine(word.Substring(count));
                    break;
                }
                count += 10;
            }
        }
    }
}
  • Substring(int startIndex) : 시작 인덱스 ~ 나머지 모든 문자열 return
  • Substring(int startIndex, int length) : 시작 인덱스 ~ 입력된 길이까지 문자열 return

0개의 댓글