17
Is there a Dart equivalent to C++'s "\n"?
In the following example:
for(int j=0;j<readLines.length;j++)
{
outputFile.writeAsStringSync(readLines[j], mode: FileMode.APPEND);
}
I would like to have the text that's in "readLines[j]" in separate lines. How could this be done?
For example:
readLines is a List of Strings, and it contains: "Hey my name is Cheshie", and "Thanks guys for trying to help".
In the code above, I am trying to write the content of the list into a file, using "outputFile", and I would like it to be written as follows:
Hey my name is Cheshie
Thanks guys for trying to help
That is, every readLines[j] should be written in a separate line.
Thanks.
The code:
import 'dart:io';
void func (String foldername)
{
Directory thisFolder = new Directory (foldername);
List<File> files = thisFolder.listSync(recursive:false);
int number=1;
String oldContent='';
String newContent='';
String concatenate='';
String name='';
int nameStart;
int nameLength;
for (int i=0; i<files.length; i++)
{
if (files[i].name.endsWith('.in'))
{
oldContent=files[i].readAsStringSync(Encoding.UTF_8);
newContent=number.toString();
var Strings=[newContent, oldContent];
concatenate=Strings.join();
files[i].writeAsStringSync(concatenate);
number++;
}
// =====================Here begins the relevant part==================
nameLength=files[i].name.length;
nameStart=files[i].name.lastIndexOf('\\', nameLength);
name=files[i].name.slice(nameStart+1, nameLength);
if (name.compareTo('hello.in')==0)
{
File outputFile=new File('hello.out');
if (outputFile.existsSync())
{
outputFile.deleteSync();
}
outputFile.createSync();
List<String> readLi