www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to Skip some field/word in formattRead?

reply Ky-Anh Huynh <saigon example.net> writes:
Hi,

Is it possible to read just the second word from an input string 
and skip all others?

     "one two three".formattedRead!("%s %s", _, saveme)

The point is I want to skip the first/third word (`one`, `third`) 
and read the second word (`two`) into the variable `saveme`. For 
now I have to declare temporary reference

     string _;
     "one two three".formattedRead!("%s %s %s", _, saveme, _);

Well, `_` is acceptable; in my example, the value of `_` would be 
`three[\n]`

Is there any better/cleaner way?

Thanks for your reading.
Sep 17
parent kdevel <kdevel vogtner.de> writes:
On Sunday, 17 September 2017 at 13:53:26 UTC, Ky-Anh Huynh wrote:
 Is it possible to read just the second word from an input 
 string and skip all others?

     "one two three".formattedRead!("%s %s", _, saveme)
--- import std.range; auto saveme = "one two three".split.array [2]; ---
Sep 17