digitalmars.D.learn - Using import to read a DOS file and then mapping the records to a
- Gary Miller (22/22) Mar 27 2014 Once you read a text file using
- bearophile (7/11) Mar 27 2014 import std.string;
Once you read a text file using auto MyDictionary = import ("dictionary.txt"); how can you parse this into a string array stripping the CrLf from the end of each line? I suspect there is some variant of the split library function that will parse it into a string array for me but because DOS lines end with the CrLf which is 2 characters I'm not sure if there is a way to do this with a one line call to a lib function. And as I understand it with the import this file is read in at compile time so after it has been parsed into the string array, is there a way to free the storage that was used by the variable MyDictionary. I like this method because it minimizes the number of files I have to distribute with my executable and prevents users from modifying the files but I don't really want to keep 2 copies of the data (imported and string array) in my program as the files brought in will be quite large. I realize I could just read it old school a record at a time but that's usually slower and requires a bit more code. Also if the files I am reading in have include references #include filename are the any lib calls that can read in the main file and expand the #include files as it reads.
Mar 27 2014
Gary Miller:Once you read a text file using auto MyDictionary = import ("dictionary.txt"); how can you parse this into a string array stripping the CrLf from the end of each line?import std.string; immutable myDictionary = import("dictionary.txt").splitLines; //pragma(msg, myDictionary); void main() {} Bye, bearophile
Mar 27 2014