fixed line breaks using the '\n' sequence not working
This commit is contained in:
parent
1fa8fcec64
commit
3035c59a88
1 changed files with 7 additions and 0 deletions
|
@ -2,22 +2,29 @@ using System;
|
|||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
// make sure fortune directory exists
|
||||
var resourcePath = "/usr/share/fortune-cs/";
|
||||
if(!Directory.Exists(resourcePath)) {
|
||||
Console.WriteLine("fortune-cs: directory '/usr/share/fortune-cs/' does not exist");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// pull file list
|
||||
var files = Directory.GetFiles(resourcePath, "*.txt");
|
||||
|
||||
var prng = RandomNumberGenerator.Create();
|
||||
|
||||
// choose a file and line
|
||||
var file = files[RandomNumberGenerator.GetInt32(files.Length)];
|
||||
var lines = File.ReadAllLines(file);
|
||||
var line = lines[RandomNumberGenerator.GetInt32(lines.Length)];
|
||||
|
||||
prng.Dispose();
|
||||
|
||||
// process escape codes
|
||||
line = line.Replace("\\n", "\n");
|
||||
|
||||
// write
|
||||
Console.WriteLine(line);
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue