Menu
Coddy logo textTech

텍스트를 단어로 분리하기

Coddy Dart 여정의 로직 & 흐름 섹션에 포함된 레슨 — 65개 중 53번째.

challenge icon

챌린지

쉬움

텍스트 분석기 프로젝트를 계속 진행하면서, 이제 단어 분할 기능을 구현하게 됩니다. 이 단계에서는 텍스트를 개별 단어로 분해하여, 향후 레슨에서 진행할 단어 수준 분석의 기초를 마련합니다.

  1. 이전 설정에서 사용한 textToAnalyze 변수를 사용하세요.
  2. 문자 수 세기 단계에서 사용한 totalCharacters 변수를 사용하세요.
  3. 공백 문자를 구분자로 사용하는 split() 메서드를 사용하여 텍스트를 개별 단어로 분할하세요.
  4. 결과로 나온 단어 리스트를 wordList라는 변수에 저장하세요.
  5. 단어 분할 분석 결과를 아래에 표시된 형식과 정확히 일치하게 출력하세요.
  6. 원본 텍스트, 문자 수, 그리고 적절한 형식을 갖춘 단어 리스트를 표시하세요.

예를 들어, 텍스트 분석기가 "Hello world!"로 설정되었다면, 프로그램은 다음과 같이 출력해야 합니다:

Text Analysis Tool - Word Splitting
====================================
Analyzing text: "Hello world!"
Total characters: 12
====================================
Word Splitting Results:
Words found: [Hello, world!]
====================================
Word splitting completed successfully.

텍스트 분석기가 "The quick brown fox"로 설정되었다면, 프로그램은 다음과 같이 출력해야 합니다:

Text Analysis Tool - Word Splitting
====================================
Analyzing text: "The quick brown fox"
Total characters: 19
====================================
Word Splitting Results:
Words found: [The, quick, brown, fox]
====================================
Word splitting completed successfully.

텍스트 분석기가 "Programming is fun!"으로 설정되었다면, 프로그램은 다음과 같이 출력해야 합니다:

Text Analysis Tool - Word Splitting
====================================
Analyzing text: "Programming is fun!"
Total characters: 19
====================================
Word Splitting Results:
Words found: [Programming, is, fun!]
====================================
Word splitting completed successfully.

프로그램은 문자열에 split(' ') 메서드를 사용하여 공백으로 구분된 개별 단어로 분리해야 합니다. 결과 리스트에는 각 단어가 별도의 문자열 요소로 포함되며, 이는 다음 레슨에서 단어 수 계산 및 분석에 사용됩니다. 구두점은 해당 단어에 붙은 상태로 유지된다는 점에 유의하세요.

직접 해보기

import 'dart:io';

void main() {
  String? textToAnalyze = stdin.readLineSync();
  
  int totalCharacters = textToAnalyze!.length;
  
  print('Text Analysis Tool - Character Count');
  print('====================================');
  print('Analyzing text: "$textToAnalyze"');
  print('====================================');
  print('Character Analysis Results:');
  print('Total characters (including spaces): $totalCharacters');
  print('====================================');
  print('Character counting completed successfully.');
}

로직 & 흐름의 모든 레슨