Advertisement
fooker

dart_double_the_words

Jul 25th, 2023
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.78 KB | None | 0 0
  1. import 'dart:io';
  2. import 'package:okay/okay.dart';
  3. void main(List <String> args){
  4.   if (args.length!=2){
  5.     print("please provide valid inputs!");
  6.     return;
  7.   }
  8.   final input = File(args[1]);
  9.   if (!input.existsSync()){
  10.     print("please create the input file!");
  11.   }
  12.   try{
  13.     String inputcontent = input.readAsStringSync();
  14.     String modifiedcontent = modify(inputcontent);
  15.     input.writeAsStringSync(modifiedcontent);
  16.   } catch(e){
  17.     print("oops!");
  18.   }
  19.   return ;
  20. }
  21.  
  22. String modify(String s){
  23.   final lines = s.split('\n');
  24.   List<String> keywords = [];
  25.   for (String line in lines){
  26.     List words = line.split(' ');
  27.     for (String word in words){
  28.       keywords.add(word);
  29.       keywords.add(word);
  30.     }
  31.   }
  32.   final m = keywords.join('\n');
  33.   return m;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement