print() without a newline in Dart?

Dart

Dart Problem Overview


In Dart, I am using print() to write content to the console.

Is it possible to use print() without it automatically adding a newline to the output?

Dart Solutions


Solution 1 - Dart

You can use stdout:

import "dart:io";
stdout.write("foo");

will print foo to the console but not place a \n after it.

You can also use stderr. See:

https://stackoverflow.com/questions/12181658/how-can-i-print-to-stderr-in-dart-in-a-synchronous-way

Solution 2 - Dart

You cannot customize the print() to prevent printing a newline in Dart (as in Python by using 'end' argument). To achieve this in Dart, use stdout.write() function, like

stdout.write("<your_message>");

Solution 3 - Dart

Have a look are the dcli package you can use the echo function.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1869559View Question on Stackoverflow
Solution 1 - DartShailen TuliView Answer on Stackoverflow
Solution 2 - DartbrahmdevpandeyView Answer on Stackoverflow
Solution 3 - DartBrett SuttonView Answer on Stackoverflow