Thread overview | ||||||
---|---|---|---|---|---|---|
|
December 03, 2018 File .. byLine | ||||
---|---|---|---|---|
| ||||
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. |
December 03, 2018 Re: File .. byLine | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joel | 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`. |
December 03, 2018 Re: File .. byLine | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nicholas Wilson | 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:
>> [...]
>
> 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`.
Oh, I was using std.algorithm's 'stripLeft' instead of std.string's 'stripLeft'.
|
December 03, 2018 Re: File .. byLine | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joel | On 12/3/18 2:03 AM, Joel wrote:
> 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:
>>> [...]
>>
>> 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`.
>
> Oh, I was using std.algorithm's 'stripLeft' instead of std.string's 'stripLeft'.
Interesting. I can see the reason too -- there is no "should be stripped" property for all types, just character types (is it a space).
-Steve
|
Copyright © 1999-2021 by the D Language Foundation