digitalmars.D.learn - File .. byLine
- Joel (13/13) Dec 02 2018 I can't seem to get this to work!
- Nicholas Wilson (4/18) Dec 02 2018 https://run.dlang.io/is/h0ArAB
- Joel (3/8) Dec 02 2018 Oh, I was using std.algorithm's 'stripLeft' instead of
- Steven Schveighoffer (4/15) Dec 03 2018 Interesting. I can see the reason too -- there is no "should be
I can't seem to get this to work! ``` foreach(line; File("help.txt").byLine) { writeln(line.stripLeft); ``` With the code above, I get this compile error: source/app.d(360,36): Error: template std.algorithm.mutation.stripLeft cannot deduce function from argument types !()(char[]), candidates are: /usr/local/opt/dmd/include/dlang/dmd/std/algorithm/mutation.d(2602,7): std.algorithm.mutation.stripLeft(Range, E)(Range range, E element) if (isInputRange!Range && is(typeof(range.front == element) : bool)) /usr/local/opt/dmd/include/dlang/dmd/std/algorithm/mutation.d(2610,7): std.algorithm.mutation.stripLeft(alias pred, Range)(Range range) if (isInputRange!Range && is(typeof(pred(range.front)) : bool)) I just want to use each 'line' variable as a string?! I've tried 'byLineCopy', and 'line.to!string'. I've looked at documentation.
Dec 02 2018
On Monday, 3 December 2018 at 06:09:21 UTC, Joel wrote:I can't seem to get this to work! ``` foreach(line; File("help.txt").byLine) { writeln(line.stripLeft); ``` With the code above, I get this compile error: source/app.d(360,36): Error: template std.algorithm.mutation.stripLeft cannot deduce function from argument types !()(char[]), candidates are: /usr/local/opt/dmd/include/dlang/dmd/std/algorithm/mutation.d(2602,7): std.algorithm.mutation.stripLeft(Range, E)(Range range, E element) if (isInputRange!Range && is(typeof(range.front == element) : bool)) /usr/local/opt/dmd/include/dlang/dmd/std/algorithm/mutation.d(2610,7): std.algorithm.mutation.stripLeft(alias pred, Range)(Range range) if (isInputRange!Range && is(typeof(pred(range.front)) : bool)) I just want to use each 'line' variable as a string?! I've tried 'byLineCopy', and 'line.to!string'. I've looked at documentation.https://run.dlang.io/is/h0ArAB works for me. If you want it as a string not char[] then byLineCopy should work, if not just `.idup` `line`.
Dec 02 2018
On Monday, 3 December 2018 at 06:55:50 UTC, Nicholas Wilson wrote:On Monday, 3 December 2018 at 06:09:21 UTC, Joel wrote:Oh, I was using std.algorithm's 'stripLeft' instead of std.string's 'stripLeft'.[...]https://run.dlang.io/is/h0ArAB works for me. If you want it as a string not char[] then byLineCopy should work, if not just `.idup` `line`.
Dec 02 2018
On 12/3/18 2:03 AM, Joel wrote:On Monday, 3 December 2018 at 06:55:50 UTC, Nicholas Wilson wrote:Interesting. I can see the reason too -- there is no "should be stripped" property for all types, just character types (is it a space). -SteveOn Monday, 3 December 2018 at 06:09:21 UTC, Joel wrote:Oh, I was using std.algorithm's 'stripLeft' instead of std.string's 'stripLeft'.[...]https://run.dlang.io/is/h0ArAB works for me. If you want it as a string not char[] then byLineCopy should work, if not just `.idup` `line`.
Dec 03 2018