Thread overview | |||||
---|---|---|---|---|---|
|
September 19, 2017 formattedRead can't work with tab delimiter input | ||||
---|---|---|---|---|
| ||||
Hi, I want to read two fields from STDIN string key; double value; line_st.formattedRead!"%s %f"(key, value); However, if the input line contains \t and it doesn't contain any space, the code doesn't work as expected. If there is a space, it works well a[space]1 # work, key => a, value => 1 b[space][tab]2 # work, key => b, value => 2 c[tab]3 # not work, key => c[tab]3, value => nan Can you please help? Thanks a lot. PS: My program is found here https://github.com/icy/dusybox/blob/master/src/plotbar/main.d#L59 |
September 19, 2017 Re: formattedRead can't work with tab delimiter input | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ky-Anh Huynh | On Tuesday, 19 September 2017 at 13:28:22 UTC, Ky-Anh Huynh wrote:
> Hi,
>
> I want to read two fields from STDIN
>
> string key;
> double value;
> line_st.formattedRead!"%s %f"(key, value);
Well it's so different from C. I would use this:
---
auto t = line_st.split.join (' ');
t.formattedRead!"%s %f"(key, value);
---
|
September 19, 2017 Re: formattedRead can't work with tab delimiter input | ||||
---|---|---|---|---|
| ||||
Posted in reply to kdevel | On Tuesday, 19 September 2017 at 20:04:36 UTC, kdevel wrote: > On Tuesday, 19 September 2017 at 13:28:22 UTC, Ky-Anh Huynh wrote: >> Hi, >> >> I want to read two fields from STDIN >> >> string key; >> double value; >> line_st.formattedRead!"%s %f"(key, value); > > Well it's so different from C. I would use this: > > --- > auto t = line_st.split.join (' '); > t.formattedRead!"%s %f"(key, value); > --- Yes it's possible. It's a little weird and it seems the "feature" (or bug) is not documented on https://dlang.org/phobos/std_format.html. Why a tab (`\t`) isn't considered as a space? |
Copyright © 1999-2021 by the D Language Foundation