Longest Word in Dart

Published on 04 October 2025 (Updated: 04 October 2025)

Welcome to the Longest Word in Dart page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

//Issue 4972

void main(List<String> argv){
  const String error_message = "Usage: please provide a string";
  if (argv.isEmpty || argv[0].isEmpty){
    print(error_message);
    return;
  }

  String sentence = argv[0];
  String raw = sentence.replaceAll(r'\t', '\t').replaceAll(r'\r', '\r').replaceAll(r'\n', '\n');
  List<String> words = raw.split(RegExp(r'\s+'));
  int max_length= 0;

  for (String each_word in words){
    if (each_word.length > max_length){
      max_length = each_word.length;
    }
  }
  print(max_length);
}

Longest Word in Dart was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.