Menu
Coddy logo textTech

단어 수 세기

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

challenge icon

챌린지

쉬움

텍스트 분석기 프로젝트를 계속 진행하면서, 이제 단어 계산 기능을 구현하게 됩니다. 이 단계에서는 이전 레슨의 단어 분리 작업을 바탕으로 텍스트의 총 단어 수를 계산합니다.

  1. 이전 설정에서 사용한 textToAnalyze 변수를 사용하세요.
  2. 문자 계산 단계에서 사용한 totalCharacters 변수를 사용하세요.
  3. 단어 분리 단계에서 사용한 wordList 변수를 사용하세요.
  4. 단어 목록의 .length 속성을 사용하여 총 단어 수를 계산하세요.
  5. 단어 수를 totalWords라는 변수에 저장하세요.
  6. 단어 계산 분석 결과를 아래에 표시된 정확한 형식으로 출력하세요.
  7. 원본 텍스트, 문자 수, 단어 목록, 단어 수를 적절한 형식으로 표시하세요.

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

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

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

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

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

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

프로그램은 텍스트를 분리한 후 몇 개의 단어가 발견되었는지 확인하기 위해 단어 목록의 .length 속성을 사용해야 합니다. 이 단어 수는 텍스트의 복잡성에 대한 필수 정보를 제공하며, 다음 레슨에서 다른 분석 지표와 함께 사용될 것입니다.

직접 해보기

import 'dart:io';

void main() {
  String? textToAnalyze = stdin.readLineSync();
  int totalCharacters = textToAnalyze!.length;
  
  List<String> wordList = textToAnalyze.split(' ');
  
  print('Text Analysis Tool - Word Splitting');
  print('====================================');
  print('Analyzing text: "$textToAnalyze"');
  print('Total characters: $totalCharacters');
  print('====================================');
  print('Word Splitting Results:');
  print('Words found: $wordList');
  print('====================================');
  print('Word splitting completed successfully.');
}

로직 & 흐름의 모든 레슨