Menu
Coddy logo textTech

Counting Characters

Part of the Logic & Flow section of Coddy's Dart journey — lesson 52 of 65.

challenge icon

Challenge

Easy

Building on your text analyzer foundation, now you'll implement the character counting functionality. This step will calculate the total number of characters in your text, including letters, spaces, punctuation, and any other symbols.

  1. Use the textToAnalyze variable from your previous setup
  2. Calculate the total number of characters in the text using the .length property
  3. Store the character count in a variable called totalCharacters
  4. Display the character analysis results in the exact format shown below
  5. Show both the original text and the character count with proper formatting

For example, if your text analyzer was set up with "Hello world!", your program should output:

Text Analysis Tool - Character Count
====================================
Analyzing text: "Hello world!"
====================================
Character Analysis Results:
Total characters (including spaces): 12
====================================
Character counting completed successfully.

If your text analyzer was set up with "The quick brown fox jumps over the lazy dog", your program should output:

Text Analysis Tool - Character Count
====================================
Analyzing text: "The quick brown fox jumps over the lazy dog"
====================================
Character Analysis Results:
Total characters (including spaces): 43
====================================
Character counting completed successfully.

If your text analyzer was set up with "Programming is fun!", your program should output:

Text Analysis Tool - Character Count
====================================
Analyzing text: "Programming is fun!"
====================================
Character Analysis Results:
Total characters (including spaces): 19
====================================
Character counting completed successfully.

Your program should use the .length property on the string to count all characters, including letters, numbers, spaces, punctuation marks, and any other symbols. This character count will be used as a foundation for more advanced text analysis in the upcoming lessons.

Try it yourself

import 'dart:io';

void main() {
  // Read the input text
  String? inputText = stdin.readLineSync();
  
  // Create the textToAnalyze variable
  String textToAnalyze = inputText ?? '';
  
  // TODO: Write your code below to display the text analysis tool setup
  print('Text Analysis Tool - Setup Complete');
  print('====================================');
  print('Original text loaded for analysis:');
  print('"$textToAnalyze"');
  print('====================================');
  print('Text analyzer is ready to process your data!');
  print('Setup completed successfully.');
}

All lessons in Logic & Flow